class jj{
public static void main(String arg[]){
boolean a=true;
boolean b=false;
boolean c=true;
if(a==true)
if(b==true)
if(c==true)
System.out.println("some things are true in this world");
else
System.out.println("nothing is true in this world");
else if(a&&(b=c))
System.out.println("it's top confusing to tell what is true and what is false");
else
System.out.println("hey this won't compile");
}
}
public static void main(String arg[]){
boolean a=true;
boolean b=false;
boolean c=true;
if(a==true)
if(b==true)
if(c==true)
System.out.println("some things are true in this world");
else
System.out.println("nothing is true in this world");
else if(a&&(b=c))
System.out.println("it's top confusing to tell what is true and what is false");
else
System.out.println("hey this won't compile");
}
}
public static void main(String arg[]) {
boolean a = true;
boolean b = false;
boolean c = true;
if (a == true)
if (b == true)
if (c == true)
System.out.println("some things are true in this world");
else
System.out.println("nothing is true in this world");
else if (a && (b = c))
System.out
.println("it's top confusing to tell what is true and what is false");
else
System.out.println("hey this won't compile"); }
}
1-if
2-if
3-if
3-else
2-else
1-else
就这个判断顺序
eclipse格式化好工具,楼上提到了,再提一次,可以让代码格式规范化
if (b == true){
if (c == true){
System.out.println("some things are true in this world");
} else {
System.out.println("nothing is true in this world");
}
} else {
if (a && (b = c)){
System.out.println("it's top confusing to tell what is true and what is false");
} else {
System.out.println("hey this won't compile");
}
}
}
else总与上边未配对的if答配
新手总是容易出这种错误
建议最好使用IF elseif else
这种形式就不会犯这种低级错误