Created
December 31, 2016 11:35
-
-
Save fanqi/b4e515c4ffc843d40650fe40351b6ef4 to your computer and use it in GitHub Desktop.
java逻辑运算符
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
b1:false
b2:true
长路与运算:false
b1:false
短路与运算:false
b3:true
b4:true
长路或运算:true
b3:true
短路或运算:true
b5:false
非运算:true