标签:
class demo {
public static void main(String[] args) {
//&,|,^,!
int a = 10;
int b = 20;
int c = 30;
//逻辑与 & 并且 and 遇到false则false
System.out.println(a < b & b < c); //true & true = true
System.out.println(a < b & b > c); //true & false = false
System.out.println(a > b & b < c); //false & true = false
System.out.println(a > b & b > c); //false & false = false
//逻辑 | 或 or 遇到 true 则 true
System.out.println(a > b | b > c); //true & true = true
System.out.println(a > b | b > c); //true & false = true
System.out.println(a > b | b > c); //false & true = true
System.out.println(a > b | b > c); //false & false = false
//逻辑 异 ^ 两边相同为false,两边不同为true
System.out.println(a > b ^ b > c); //true ^ true = false
System.out.println(a > b ^ b > c); //true ^ false = true
System.out.println(a > b ^ b > c); //false ^ true = true
System.out.println(a > b ^ b > c); //false ^ false = false
//逻辑 非 ! 相当于取反
System.out.println(!true);
System.out.println(!!true);
JAVA_学习第二天(三)[ 逻辑运算符(&)(|)(^)(!)]
标签:
原文地址:http://www.cnblogs.com/dlbm/p/5974856.html