// Project 2-2: a truth table for the logical operators class LogicalOpTable { public static void main(String args[]) { System.out.println("P\tQ\tAND\tOR\tXOR\tNOT"); print10Row(true, true); print10Row(true, false); print10Row(false, true); print10Row(false, false); } static void print10Row(boolean p, boolean q){ System.out.print(convertToInt(p) + "\t" +convertToInt(q)+"\t"); System.out.print(convertToInt(p&q) + "\t" +convertToInt(p|q) + "\t"); System.out.println(convertToInt(p^q) + "\t" +convertToInt(!p)); } static int convertToInt(boolean b){ if(b) return 1; else return 0; } static void printRow(boolean p, boolean q){ System.out.print(p + "\t" +q +"\t"); System.out.print((p&q) + "\t" +(p|q) + "\t"); System.out.println((p^q) + "\t" +(!p)); } }