java05运算符
逻辑运算后的数据类型
long a = 123456789456l;
int b = 110;
short c = 11;
byte d = 8;
double e = 456;
System.out.println(a+b+c+d);//123456789585;long类型
System.out.println(b+c+d);//129;int类型
System.out.println(c+d);//19;int类型
System.out.println(c+d+e);//475.0;double类型
//有long就是long,有double就是double,没有就是int
double pow = Math.pow(2,3);//幂运算
逻辑运算短路
int c = 5;
boolean d = (c<4)&&(c++<4);
System.out.println(d);//5
System.out.println(c);//false,短路了,不执行c++
A = 0011 1100
B = 0000 1101
----------------------
A&B 与 0000 1100
A|B 或 0011 1101
A^B 异或 0011 0011
~B非 1111 0010
A ? B:C 如果A为真执行B,否则执行C
2*8怎么运算最快
2*2*2*2
位运算效率高
<< *2
>> /2
字符串+
int a = 10;
int b = 20;
System.out.println(""+a+b);//1020,按照字符串相加
System.out.println(a+b+"");//30,先相加在变为字符串

浙公网安备 33010602011771号