class test {
public static void main (String[] args) {
boolean a = false;
boolean b = true;
if (a && a || b) {
System.out.println(true);
}
}
} //--why it always true????o/p is true but why??
操作顺序。
&&
具有比更高的优先级||
,因此首先被评估。您的if
条件可以重写如下:
(a && a) || b
(false && false) || true
false || true
true
这种情况将永远是false || true
它总是true
为你列出的条件。
检查这里对从Oracle的官方表列出了所有运营商的优先级。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句