public class AndOperator {
public static void main(String[] arg) {
int value = 8;
int count = 10;
int limit = 11;
if (++value % 2 == 0 && ++count < limit) {
System.out.println("here");
System.out.println(value);
System.out.println(count);
} else{
System.out.println("there");
System.out.println(value);
System.out.println(count);
}
}
}
我得到输出为
there
9
10
请解释 count 是 10....?
最佳答案
&&
是 short-circuit operator .如果第一个表达式的计算结果为真,它只会计算第二个表达式。
由于 ++value % 2 == 0
为假,因此它不会计算第二个表达式,因此不会增加 count
。
关于java - 解释 if (++value % 2 == 0 &&++count < limit) in java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18599757/