我写了个测试代码,如下:public class Test2 { public static void main(String[] args) {
String str="null";
if(str==null){
System.out.println("null");
}else(str.length()==0){ //编译出错
System.out.println("zero");
}
System.out.println("some");
}
}
编译不通过,不知道是为什么,请大虾帮忙解释一下?谢谢
String str="null";
if(str==null){
System.out.println("null");
}else(str.length()==0){ //编译出错
System.out.println("zero");
}
System.out.println("some");
}
}
编译不通过,不知道是为什么,请大虾帮忙解释一下?谢谢
改为else if(str.length()==0)
(这是SCJP上的题,我都快被这些小问题快搞崩溃了:))
}
基本语法。
你发现了新大陆了...
else if(...)
仔细看仔细学,不是照抄,要理解