【发布时间】:2013-12-11 02:29:20
【问题描述】:
如果我有以下逻辑来检查两个真或两个假但忽略其他的,我写:
if (a) {
if (b) {
// do something when both true
}
} else if (!b) {
// do something when both false
}
这是你用java写的最简单的吗?
我当然会写
if (a && b) {
// do something when both true
} else if (!a && !b) {
// do something when both false
}
但我在想是否有可能只使用一个 if 条件和 else 没有条件来实现这一点,例如
if (some condition) {
// do something when both true
} else { // <-- check! only else, no more condition
// do something when both false
}
不可能当然是这个问题的可接受答案(如果附有解释)
谢谢
【问题讨论】:
标签: java comparison logic