字符串连接符
public class Demo008 {
public static void main(String[] args) {
int a=10;
int b=20;
System.out.println(" "+a+b);
System.out.println(a+b+" ");
System.out.println(a+b+" "+a+b);
}
}
输出:
1020 30
30 1020
可知:当有String类型时,后面的字符都按照String处理
条件运算符
?:
x ? y:z 代表如果x为true 则结果为y,x为false 则结果为z,其实就是一种简略的if....else...写法,实际运用还是这个常用,会使代码更加简略,可读性更高。
public class Demo009 {
public static void main(String[] args) {
int x=50;
String h=x<60?"不及格":"及格";
System.out.println(h);
}
}
输出:
不及格