与或非 左移右移
public class Boolean01 {
public static void main(String[] args) {
// 与(and) 或(or) 非 (取反)
boolean a = true;
boolean b = false;
System.out.println("a&&b:"+(a&&b)); // a&&b:false 逻辑与运算:两个都为true时,结果为 true,否则为 false,满足短路运算
System.out.println("a||b:"+(a||b)); // a||b:true 逻辑或运算,两者中有一个为true时,则结果为 true,满足短路运算
System.out.println("!(a&&b):"+!(a&&b)); // !(a&&b):true 逻辑非运算,对true进行非运算时,结果为false,对false进行非运算时,结果为true
// 短路运算 如果
int c = 4;
boolean d = (c<3)&&(++c>3);
System.out.println("d="+d); // d=true
System.out.println("c="+c); // c=4
/*
A = 0011 1100
B = 0000 1101
-----------------------------------
A&B = 0000 1100
A|B = 0011 1101
~B = 1111 0010
2*8 = 16 2*2*2*2
>> 右移除2
<< 左移乘2
0000 0000 0
0000 0001 1
0000 0010 2
0000 0011 3
0000 0100 4
0000 1000 8
0001 0000 16
*/
System.out.println(2<<3); // 16
System.out.println(32>>3); // 4
}
}