逻辑运算符
&& || !
package operator;
/**
* @version: java version 1.8
* @Author: Mr Theroux
* @description:
* @date: 2024-08-20 9:33
*/
public class Demo05 {
public static void main(String[] args) {
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));//!反
}
}
& | ^ ~ << >>
package operator;
/**
* @version: java version 1.8
* @Author: Mr Theroux
* @description:
* @date: 2024-08-20 10:00
*/
public class Demo06 {
public static void main(String[] args) {
/*
A = 0011 1100;
B = 0000 1101;
A&B = 0000 1100;
A|B = 0011 1101;
A^B = 0011 0001; 位置相同则为0,否则为1
~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
*/
System.out.println(2<<3);
}
}
标签:逻辑,0000,0011,System,运算符,version,&&,out
From: https://www.cnblogs.com/theroux/p/18368893