有没有让程序说出哪个条件是正确的?
public static void main(String[] args) throws IOException, InterruptedException {
Boolean a = true;
Boolean b = false;
Boolean c = null;
if (a == true || b == false || c == true) {
System.out.println("Test");
}
}
由于a
是唯一正确的,因此有办法让它打印"a is the only condition that is correct"
答案 0 :(得分:1)
if (a) {
System.out.println("a is the condition that is correct");
}
//Edit by comment. Thanks
if (!b) {
System.out.println("b is the condition that is correct");
}
if (c) {
System.out.println("c is the condition that is correct");
}