`
//二元运算符
int a=10;
int b=20;
int c=30;
int d=40;
System.out.println(a+b);//30
System.out.println(a-b);//-10
System.out.println(a*b);//200
System.out.println(a/(double)b);//0.5
`
`
long a= 1000000000L;
int b=132;
short c=10;
byte d=8;
System.out.println(a+b+c+d);//long 1000000150
System.out.println(b+c+d);//int 150
System.out.println(c+d);//int 18
`
`
//关系运算符返回的结果 false true 布尔值 if联合用
int a=10;
int b=20;
int c=22;
System.out.println(c%a);//取余数 模运算 2
System.out.println(a<b);//true
System.out.println(a>b);//false
System.out.println(a==b);//false
System.out.println(a!=b);//true
`
`
//自增++ 自减-- 一元运算符
int a=3;
int b=a++;//先用后加
int c=++a;//先加后用
System.out.println(a);
System.out.println(b);
System.out.println(c); //a=5 b=3 c=5
//幂运算 2^3=8 工具类操作运算 eg:Math类
double pow = Math.pow(2, 3);
System.out.println(pow);//8.0
`
`
//与(and) 或(or) 非(取反)
boolean a=true;
boolean b=false;
System.out.println("a&&b:"+(a&&b));//逻辑与运算:两个变量个都为真,结果才为true
System.out.println("a||b:"+(a||b));//逻辑或运算:两个变量有一个为真,结果才为true
System.out.println("!(a&&b):"+!(a&&b));//如果真,则变为假。如果假,则变为真。
//短路运算
int c=5;
boolean d=(c<4&&c++<4);//发生短路后面不执行 c++不执行
System.out.println(d);//结果直接判断为false
System.out.println(c);//结果还是五 你看看不变吧
/*
A = 0011 1100
B = 0000 1101
----------------------------
A&B=0000 1100
A|B=0011 1101
A^B=0011 0001
~B =1111 0011
常见面试题
2*8 = 16 2*2*2 效率极高!!!
<<左移 就是*2
>>右移 就是/2
0000 0000 0
0000 0001 1
0000 0010 2
0000 0011 3
0000 0100 4
0000 0101 5
0000 0110 6
0000 0111 7
0000 1000 8
1000 0000 16
*/
System.out.println(2<<3);//16
`
`
int a=10;
int b=10;
a+=b; //a=a+b
System.out.println(a);
//字符串连接符 + , String
System.out.println(a+b);
System.out.println(""+a+b);//2010
System.out.println(a+b+"");//30
`
`
//x ? y: z
//如果x=true,则结果为y,否则结果为z
int socre=80;
String type = socre <60 ?"不及格":"及格";//掌握
System.out.println(type); //及格
`
原文:https://www.cnblogs.com/Mr42/p/14709881.html