条件运算符 ? : (三元运算符)
//三元运算符 public class Day08 { public static void main(String[] args) { // x? y: z // 如果x的值是true真的x=true则结果为y 否则结果为z int score =50; String tepe =score <60 ?"不及格" :"及格了";//必须掌握!!!可以让代码更加精简便于理解 // if 以后会用 System.out.println(tepe); } }
扩展运算符
+= , -= , *= , /=
package operator; //扩展运算符 public class Day07 { public static void main(String[] args) { int a =10; int b =20; a+=b; //上面得 a=a+b a=a-b; //上面的a=a-b System.out.println(a); System.out.println(b); //字符串连接符 + (""),在加号类型的两侧有一方出现string类型他就都会转换成string进行连接 System.out.println(a+b); System.out.println(""+a+b);//1020结果 //上下两个有什么区别如果换这个空字符串("")在前面才会进行拼接如在后面 前面依旧运算不会进行拼接 System.out.println(a+b+"");//30结果 } }