- 算数运算符:+,-,*,、,%,++,—
- 赋值运算符:=
- 关系运算符:>,<,>=,<=,==,!=,instanceof
- 逻辑运算符:&&,||,!
- 位运算符:&,|,^,~,>>,<<,>>>
- 条件运算符:?:
- 扩展赋值运算符:+=,-=,*=,/=
自增和自减
public class Demo2 {
public static void main(String[] args) {
//一元运算符
int a=3;
int b=a++; //执行这行代码后,先给b赋值,再自增
//a=a+1;
System.out.println(a);
int c=++a; //执行这行代码前,先自增,再给c赋值
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
+和字符串拼接
public class Demo3 {
public static void main(String[] args) {
int a=20;
int b=10;
a+=b;
a-=b;
System.out.println(a);
//字符串连接 +, String
System.out.println(a+b);
System.out.println(""+a+b);
System.out.println(a+b+""); //先算了a+b再连接字符串
}
}