Skip to content

Instantly share code, notes, and snippets.

@melvincabatuan
Created September 9, 2014 00:48
Show Gist options
  • Save melvincabatuan/5ad12a8299128b4dc0ee to your computer and use it in GitHub Desktop.
Save melvincabatuan/5ad12a8299128b4dc0ee to your computer and use it in GitHub Desktop.
Truth Table Demo
package com.dismath.truthtable;
public class TruthTable {
public static void main(String[] args) {
boolean p, q;
System.out.println("**********************************************");
System.out.println(" p \t q \t AND \t OR \t XOR \t NOT_p");
System.out.println("**********************************************");
p = false; q = false;
System.out.print(p + "\t" + q +"\t");
System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
p = false; q = true;
System.out.print(p + "\t" + q +"\t");
System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
p = true; q = false;
System.out.print(p + "\t" + q +"\t");
System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
p = true; q = true;
System.out.print(p + "\t" + q +"\t");
System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
}
}
/*
* Output:
**********************************************
p q AND OR XOR NOT_p
**********************************************
false false false false false true
false true false true true true
true false false true true false
true true true true false false
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment