&和&& 逻辑与和短路与
代码示例
public static void main(String[] args) {
/**
* 逻辑与 短路与
*/
int a = 4;
int b = 9;
if (a<1 && ++b < 20 ){
System.out.println("ok");
}
System.out.println(b);
//输出9
if (a<1 & ++ b < 20 ){
System.out.println("ok");
}
System.out.println(b);
//输出10
}
|和|| 逻辑或和短路或
!和^ 取反和逻辑异或
示例
boolean res = (4>6) ^ (6<7);
System.out.println("res = " + res);
//res = true