Skip to content

Instantly share code, notes, and snippets.

@fanqi
Created December 31, 2016 11:35
Show Gist options
  • Save fanqi/b4e515c4ffc843d40650fe40351b6ef4 to your computer and use it in GitHub Desktop.
Save fanqi/b4e515c4ffc843d40650fe40351b6ef4 to your computer and use it in GitHub Desktop.
java逻辑运算符
package xyz.fanqi.java;
public class LogicalOperator {
public static void main(String[] args) {
//长路与运算
System.out.println("长路与运算:" + (b1() & b2()));
//短路与运算
System.out.println("短路与运算:" + (b1() && b2()));
//长路或运算
System.out.println("长路或运算:" + (b3() | b4()));
//短路或运算
System.out.println("短路或运算:" + (b3() || b4()));
//非运算
System.out.println("非运算:" + !b5());
}
public static boolean b1() {
boolean result = 1 > 1;
System.out.println("b1:" + result);
return result;
}
public static boolean b2() {
boolean result = 2 > 1;
System.out.println("b2:" + result);
return result;
}
public static boolean b3() {
boolean result = 3 > 1;
System.out.println("b3:" + result);
return result;
}
public static boolean b4() {
boolean result = 4 > 1;
System.out.println("b4:" + result);
return result;
}
public static boolean b5() {
boolean result = false;
System.out.println("b5:" + result);
return result;
}
}
@fanqi
Copy link
Author

fanqi commented Dec 31, 2016

b1:false
b2:true
长路与运算:false
b1:false
短路与运算:false
b3:true
b4:true
长路或运算:true
b3:true
短路或运算:true
b5:false
非运算:true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment