三元运算符

public class demo5 {
public static void main(String[] args) {

int a = 10;
int b = 20;

a+=b;//a = a+b
a-=b;//a = a-b

System.out.println(a);


//字符串连接符
System.out.println(a+b);
System.out.println(""+a+b);//1020,在+运算符两侧有一方出现String类(字符串类)就会把其他操作数都转换为String类型,再进行连接
System.out.println(a+b+"");//30,先进行了a+b,再转换为String类


//三元运算符
//x ? y : z
//如果x==true,则结果为y,否则为z

int score = 80;
String type = score < 60 ? "不及格" : "及格";//必须掌握
System.out.println(type);



}
}
 
posted @ 2021-03-01 09:06  Joey19  阅读(34)  评论(0)    收藏  举报