/*** Truth Table *********************************************************

   This program generates a truth table for a Boolean expression.
   It uses escaped-TAB characters to line up columns.

 *************************************************************************/


public class TruthTable
{
   public TruthTable()
   {
      boolean A,B,C,truth;
      System.out.println(" A \t B \t C \t(A and not B) or not(B and C)");
      A = false;
      do
      {
         B = false;
         do
         {
            C = false;
            do
            {
               truth = (A && !B) || !(B && C) ;
               System.out.println(A + "\t" + B + "\t" + C + "\t" + truth);
               C = !C;
            } while (C);
            B = !B;
         } while (B);
         A = !A;
      }  while (A);
   }
   
   public static void main(String[] args)
   {  new TruthTable(); }
}     

/*************** Sample Output ******************************************

    A       B       C      (A and not B) or not(B and C)
   false   false   false   true
   false   false   true    true
   false   true    false   true
   false   true    true    false
   true    false   false   true
   true    false   true    true
   true    true    false   true
   true    true    true    false

(1) The expression above can be simplified.
    Figure out which of the following expressions
    is EQUIVALENT to the expression in the program:
    
      (A and not B) or (not C)
      !B and !C
      !B or !C
      !A or !B or !C

    Once you have decided on one of the expressions,
    change the program to print a Truth Table for
    that expression.
    
(2) Write an expression that prints FALSE in
    all 8 lines of the truth table.
    
(3) Write an expression that print TRUE in
    all 8 lines of the truth table.
    
(4) Change the program to write a truth table
    for 4 variables A,B,C,D.  
    Write the truth table for this expression:  
      (A and !B) or (C and !D) or (B and D).
  
 ************************************************************************/