我有这样的代码
if(a == 3) {
if(b == 4) {
// do somthing
} else {
// do an other thing
}
} else {
// do the same other thing
}
我想知道,当我在第一个 else
中时,我如何才能转到第二个 else
因为它会执行相同的代码
谢谢
最佳答案
您只想在 a==3
AND b==4
时执行 //do some
部分,因此您可以使用 &&
运算符将它们组合起来。
这样您就可以将两个条件合并为一个,并使用一个 else
子句来执行 //do an other thing
部分:
if(a == 3 && b == 4) {
// do something
} else {
// do an other thing
}
关于java - 返回父级,如果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39342719/