package base;public class Demo07 { 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); //字符串连接符 + , String System.out.println(a+b); System.out.println(""+a+b); //字符串在前,值为字符串 System.out.println(a+b+""); //字符串在后,值为数字 }}------------1030102030
2、三元运算符举例package base;public class Demo08 { public static void main(String[] args) { //三元运算符 x ? y : z //如果x==true,则结果为y,否则结果为z int score = 80; String type = score <60 ? "不及格":"及格"; //if语句实现 System.out.println(type); }}---------------及格
3.优先级()优先级高的表达式放在括号中