if(username.equals(“zxx”){}
int x = 1;
return x==1?true:false;
public static void method1(){
String username="null";
// if(username.equals("LBW")){ username为空时报空指针异常
// System.out.println("LBW");
// }
if("LBW".equals(username)){ //将username后置,在没有赋值的情况下不会报空指针异常
System.out.println("Lbw");
}
}
public static boolean method2(){
int x=1;
return x==1?true:false;
}
public static String method3(){
int x=1;
return x==1?"正确":"错误";
}
public static boolean method4(){
String str1="BBB";
String str2="BBB";
return str1.equals(str2);
}
public static int method5(){
String str1="BBB";
String str2="BBB";
return str1.compareTo(str2);
}
public static void main(String[] args) {
method1();
Boolean bool=method2();
System.out.println("bool");
String string=method3();
System.out.println("string");
Boolean bool1=method4();
System.out.println("boole");
Integer int1=method5();
System.out.println("int");
}