【发布时间】:2014-12-01 20:12:54
【问题描述】:
假设条件看起来像这样:
if (false && true)
//Code
它会在达到真之前脱离条件吗,因为假和 && 永远不会为真?
另外,如果你有这样的代码:
boolean dividesToTwo (int operand1, int operand2) {
if ((operand2 != 0) && operand1 / operand2 == 2)
return true;
return false;
}
它会按预期成功运行,还是会因为被零除而出错? (如果第二个操作数为零)
【问题讨论】:
-
&&是 条件运算符,并且按照规范要求具有短路语义。所以,是的。 -
这已经被问过了。看看这个:stackoverflow.com/questions/7199666/…
-
你试过了吗?
标签: java conditional-statements