Java学习笔记12
扩展赋值运算符:+=
-=
*=
/=
public class Demo07 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a+=b;//a=a+b
System.out.println(a);
}
}
30
a-=b(a=a-b)
a=b(a=ab)
a/=b(a=a/b)
字符串连接符
//字符串连接符 +两侧出现string(字符串类型)就把其他操作符转换成string类型并连接
System.out.println(""+a+b);
System.out.println(a+b+"");
1020
30
条件运算符(三元运算符)
public class Demo08 {
public static void main(String[] args) {
//X?Y:Z
//如果X==true则结果为y,否则结果为z
int score = 80;
String type = score < 60 ?"不及格":"及格";
System.out.println(type);
int score = 50;
String type = score < 60 ?"不及格":"及格";
System.out.println(type);
}
}
及格
不及格
浙公网安备 33010602011771号