1、算术运算符:+ - * / %(余数)++(自加1) --(自减1);
2、关系运算符:> < >= <= == !=;
3、逻辑运算符:短路与&& 短路或|| 非! 按位与& 按位或|;
4、赋值运算符:= += -= *= /= %= ;
5、条件运算符:表达式?结果1:结果2;
注意:
i++先参与运算,后自加1;
++i先自加1,后参与运算
如:
int num=30;
num+=5;
boolean flag=num<35|++num==31;
System.out.println(flag); //false
System.out.println(num); //36
++++++++++++++++++++++++++++++++++++
int num1=30,num2=50;
boolean flag=num1>=num2&&++num1>10;
System.out.println(flag); //false
System.out.println(num1); //30,注意,不是31,因为短路
int max=num1<num2?num2:num1;
System.out.println(max); //50
++++++++++++++++++++++++++++++++++++
int a=0;
a=a++;
int b=a++;
int c=b++;
System.out.println("a是:"+a); //a是1
System.out.println("b是:"+b); //b是1
System.out.println("c是:"+c); //c是0