1 package Day06; 2 3 public class Java06_1 { 4 public static void main(String[] args) { 5 //与(and) 或(or) 非(取反) 6 boolean a=true; 7 boolean b=false; 8 9 System.out.println("a&&b"+(b&&a)); 10 System.out.println("a||b"+(b||a)); 11 System.out.println("!(a&&b)"+(!(b&&a))); 12 //短路运算 逻辑运算符前面的计算如果已经能够得出结论,则后面自动跳过 13 int c=5; 14 boolean d=(c<4)&&(c++<4); 15 System.out.println(c); 16 System.out.println(d); 17 18 } 19 }
1 package Day06; 2 3 public class Java06_2 { 4 public static void main(String[] args) { 5 /* 6 A=1010 0110 7 B=1100 0011 8 A&B=1000 0010 9 A|B=1110 0111 10 A^B=1000 0010 11 ~B=0011 1100 12 13 2*8 = 2*2*2*2 14 << >> 15 0000 0000 0 16 0000 0001 1 17 0000 0010 2 18 0000 0100 4 19 0000 1000 8 20 0001 0000 16 21 2*8 =2<<3 =16 22 */ 23 int a=0b0011_1100; 24 int b=0b0000_1101; 25 System.out.println(a&b);//12=0000 1100 26 System.out.println(a|b);//61=0011 1101 27 System.out.println(a^b);//49=0011 0001 28 System.out.println(2<<3); 29 } 30 }