Skip to content

Instantly share code, notes, and snippets.

@ShmuelMofrad
Created November 29, 2017 17:36
Show Gist options
  • Save ShmuelMofrad/6491527882925153beb0789b06236af8 to your computer and use it in GitHub Desktop.
Save ShmuelMofrad/6491527882925153beb0789b06236af8 to your computer and use it in GitHub Desktop.
Truth table - AND & OR in Java
public class LogicAndOr {
public static void main(String[] args) {
boolean result;
result = isAndTrueOrFalse(true, true, true);
System.out.println("And 1: " + result);
result = isAndTrueOrFalse(false, true, true);
System.out.println("And 2: " + result);
result = isOrTrueOrFalse(true, true, true);
System.out.println("Or 1: " + result);
result = isOrTrueOrFalse(false, true, true);
System.out.println("Or 2: " + result);
result = isOrTrueOrFalse(false, false, false);
System.out.println("Or 3: " + result);
printTable();
}
static boolean isAndTrueOrFalse(boolean a, boolean b, boolean c) {
return (a && b && c);
}
static boolean isOrTrueOrFalse(boolean a, boolean b, boolean c) {
return (a || b || c);
}
static void printTable() {
System.out.println("\nA = true\tB = true\tAND is true\tOR is true");
System.out.println("\nA = true\tB = false\tAND is false\tOR is true");
System.out.println("\nA = false\tB = true\tAND is false\tOR is true");
System.out.println("\nA = false\tB = false\tAND is false\tOR is false");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment