Created
March 28, 2018 03:40
-
-
Save edwardbeckett/d17336ed10896ea3a7cf6456d6443761 to your computer and use it in GitHub Desktop.
Logical Operators Cheat Sheet
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
public class LogicalOperators { | |
/* | |
* TRUTH LOGIC | |
* | |
* X & Y | |
* (AND) | |
* | |
* AND is Only True IF BOTH OPERANDS ARE TRUE | |
* --------------------------------- | |
* |X = TRUE & Y = TRUE :: TRUE | | |
* |X = TRUE & Y = FALSE :: FALSE | | |
* |X = FALSE & Y = TRUE :: FALSE | | |
* |X = FALSE & Y = FALSE :: FALSE | | |
* --------------------------------- | |
* | |
* X | Y | |
* (INCUSIVE OR) | |
* | |
* Inclusive OR is Only False IF BOTH OPERANDS ARE FALSE | |
* --------------------------------- | |
* |X = TRUE & Y = TRUE :: TRUE | | |
* |X = TRUE & Y = FALSE :: TRUE | | |
* |X = FALSE & Y = TRUE :: TRUE | | |
* |X = FALSE & Y = FALSE :: FALSE | | |
* --------------------------------- | |
* | |
* X ^ Y | |
* (EXCLUSIVE OR) | |
* | |
* Exclusive OR is Only True IF BOTH OPERANDS ARE DIFFERENT | |
* --------------------------------- | |
* |X = TRUE & Y = TRUE :: FALSE | | |
* |X = TRUE & Y = FALSE :: TRUE | | |
* |X = FALSE & Y = TRUE :: TRUE | | |
* |X = FALSE & Y = FALSE :: FALSE | | |
* --------------------------------- | |
**/ | |
public static void main(String[] args) { | |
boolean x, y, and, or, xor; | |
x = false; | |
y = false; | |
and = x & y; | |
or = x | y; | |
xor = x ^ y; | |
System.out.println("===================="); | |
System.out.println("X = FALSE, Y = FALSE"); | |
System.out.println("===================="); | |
System.out.println("X & Y = " + and); | |
System.out.println("X | Y = " + or); | |
System.out.println("X ^ Y = " + xor); | |
x = false; | |
y = true; | |
and = x & y; | |
or = x | y; | |
xor = x ^ y; | |
System.out.println("==================="); | |
System.out.println("X = FALSE, Y = TRUE"); | |
System.out.println("==================="); | |
System.out.println("X & Y = " + and); | |
System.out.println("X | Y = " + or); | |
System.out.println("X ^ Y = " + xor); | |
x = true; | |
y = true; | |
and = x & y; | |
or = x | y; | |
xor = x ^ y; | |
System.out.println("=================="); | |
System.out.println("X = TRUE, Y = TRUE"); | |
System.out.println("=================="); | |
System.out.println("X & Y = " + and); | |
System.out.println("X | Y = " + or); | |
System.out.println("X ^ Y = " + xor); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment