逻辑运算符:&& ||

位运算符:&与、| 或、~非、^异或

1、逻辑运算会出行短路现象,即在多个逻辑运算表达式共同作用下,如果中途已经明确逻辑运算结果,则后续逻辑表达式不会再进行运算。

int b = 2, c = 3;
boolean result = (b == 2) || (c++ == 3);
System.out.println(c);
System.out.println(result);

result = (b != 2) && (c++ == 3);
System.out.println(c);
System.out.println(result);

 结果:

3
true
3
false

 2、位运算符&、|、^ 可以作用于布尔型,但~不行

3、char,byte 或者short 数值位运算时,运算结果自动转型为int,如下程序则会编译报错:Type mismatch: cannot convert from int to short

short x=1,y=2,z;
z=x&y;

  

posted on 2017-07-06 16:24  X-Man0  阅读(130)  评论(0)    收藏  举报