简体   繁体   English

有没有一种方法可以用&&或||来表示逻辑

[英]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 ?: 或诸如if?:类的语句?:

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和||序列来实现 s alone; 一个人 not ! ! operation is among operations that cannot be implemented with ands and ors. 操作属于无法使用ands和ors实施的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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