1 package Day06; 2 3 public class Java06_3 { 4 public static void main(String[] args) { 5 int a=10; 6 int b=20; 7 8 a+=b;//a=a+b 9 System.out.println(a); 10 a-=b;//a=a-b(目前a=30) 11 System.out.println(a); 12 13 //拓展:字符串连接符:"String"+a+b 将结果转化为字符串并将前后两个数字连接 14 //a+b+“String” 先计算a+b,再将结果转化成字符串类型 15 System.out.println(""+a+b); 16 System.out.println(a+b+""); 17 } 18 }
1 package Day06; 2 3 public class Java06_4 { 4 public static void main(String[] args) { 5 //三元运算符 ? : 含义同 C++ 6 int score=50; 7 String type = score <60?"不及格":"及格";//必须掌握 8 //if 条件句 9 System.out.println(type); 10 } 11 }