不晓得这题的if else 是怎么搭配的?
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 ");
}
}
------解决方案--------------------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 ");
}
}
------解决方案--------------------else和最近的一个if搭配
------解决方案--------------------你可以把它放到eclipse中格式化以下,就可以看清楚其对应关系。
------解决方案--------------------中间的if和下面的else是一组
1-if
2-if
3-if
3-else
2-else
1-else
就这个判断顺序
eclipse格式化好工具,楼上提到了,再提一次,可以让代码格式规范化
------解决方案--------------------eclipse下ctrl+shift+f
------解决方案--------------------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 ");
}
}
}
------解决方案--------------------我来说个规则吧
else总与上边未配对的if答配
新手总是容易出这种错误
建议最好使用IF elseif else
这种形式就不会犯这种低级错误