public boolean monkeyTrouble (boolean aSmile, boolean bSmile) {
if (aSmile && bSmile) {
return true;
}
if (!aSmile && !bSmile) {
return true;
}
return false;
}
我不明白为什么最后一行代码应该return false;
谁能解释一下?谢谢。
最佳答案
来自问题描述:
We are in trouble if they are both smiling or if neither of them is smiling. Return true if we are in trouble.
因此,如果他们中的一个在微笑,我们就没有麻烦。
if (aSmile && bSmile) {
return true;
}
如果他们都在笑,就掩护。并且:
if (!aSmile && !bSmile) {
return true;
}
如果他们都没有笑就掩护。这些是该方法应返回 true 的仅有的两个组合。因此,如果这两个条件都不成立,则需要返回 false。
关于java - 为什么下面的代码块应该返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52356540/