1.算数运算符
+,-,*,%,/
int a=10;
int b=20;
System.out.println(a+b); //30
System.out.println(a-b); //-10
System.out.println(a*b); //200
System.out.println(a/b); //0 默认结果为int类型 会对小数位进行舍去
System.out.println((double)a/b); //0.5 将结果转换为double
System.out.println(a%b); // a/b余数
++,–
//c++ 计算完成后进行c=c+1
//++c 计算中先进行c=c+1
//c--跟c++同理
int c=3;
int e=c++;
int e2=++c;
System.out.println(e); //3
System.out.println(e2); //5
System.out.println(c); //5
2.赋值运算符
=
int i=1; //将1赋值给i
3. 关系运算符
<, >, >=, <=, ==, !=, instanceOf
int cc=2;
int bb=3;
Operator o= new Operator();
System.out.println(cc>bb);//false
System.out.println(cc<bb);//true
System.out.println(cc==bb);//false
System.out.println(cc!=bb);//true
System.out.println(o instanceof Operator); //true
4. 逻辑运算符
&&,||, !
//逻辑运算符
boolean flag=false;
boolean flag2=true;
System.out.println(flag&&flag2); //false
System.out.println(flag||flag2); //true
System.out.println(!flag); //true
5.位运算符
&,|,^,~,>>,<<
/*
A=0011 1100
B= 0000 1101
A&B = 0000 1100
A/B = 0011 1101
A^B = 0011 0001 异或相等为0,不相等为1
~B = 1111 0010 取反
<< 右移 *2
>> 左移 /2
*/
System.out.println(2<<3);//16 *三个2
6.条件运算符
?:
//条件运算符
boolean flag3=true;
System.out.println(flag3?"成功":"失败"); //成功
7.拓展运算符
+=,-=,*=,/=
int num=1;
int num2=2;
num+=num2;// 相当于num=num+num2 其他类似
System.out.println(num);//3