1、+ 号和字符串
package operator;
public class Demo05 {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(a+b); //输出30
System.out.println(""+a+b); //输出1020,将a和b拼接了
System.out.println(a+b+""); //输出30 字符串在加法后面,所以会输出计算结果
}
}
2、三元运算符
package operator;
public class Demo06 {
public static void main(String[] args) {
//x?y:z
//如果x==true,结果为,否则结果为z
int score = 50;
String result = score<60?"不及格":"及格";
System.out.println(result);
}
}