三元運算符(x ? y : z)
public class Demo02 {
public static void main(String[] args) {
// x ? y : z
//如果x==true,則結果為y,否則為z
int score = 50;
String type = score < 60 ?"不及格":"及格";
System.out.println(type);//不及格
}
}
字符串拼接符“+”
public class Demo01 {
public static void main(String[] args) {
//字符串連接符 +
System.out.println(a+b);//30
System.out.println(""+a+b);//1020 String類型在運算之前字符串會進行拼接
System.out.println(a+b+"");//30 String在后面則不會
}
}