//逻辑运算符
public class Demo05 {
public static void main(String[] args) {
//与(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<4为false 所有c++不会被执行 为短路运算
System.out.println(d);
System.out.println(c);
}
}
public class Demo06 {
public static void main(String[] args) {
/*
A=0011 1100
B=0000 1101
-------------------------------
A&B = 0000 1100 如果两个都为1则为1 否则为0
A|B = 0011 1101 如果两个都是0则为0 如果有一个为1则为1
A^B = 0011 0001 如果两个位置相同为0 否则为1
~B = 1111 0010
2*8=16 2*2*2*2
<< *2
>> /2
*/
System.out.println(2<<3);//16
System.out.println(3<<2);//12
}
}