简体   繁体   中英

Is there a way to represent logical not with && or ||

Is there a way to represent logical not, with && or || or some statement like if or ?:

I want to implement this in some other way:

boolean isRunning = true;
startButton.setEnabled(!isRunning); // <<== ???

Assuming that you are doing this as an exercise, ternary operator lets you replace ! in a simple and straightforward way:

startButton.setEnabled(isRunning ? false : true);

As far as using && and || by themselves goes, this pair of operators is not functionally complete , ie there are operations that cannot be implemented by using a sequence of && s and || s alone; not ! operation is among operations that cannot be implemented with ands and ors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM