Source of LogicalOperators.java


  1: // Fig. 5.18: LogicalOperators.java
  2: // Logical operators.
  3: 
  4: public class LogicalOperators 
  5: {
  6:    public static void main( String args[] )
  7:    {
  8:       // create truth table for && (conditional AND) operator
  9:       System.out.printf( "%s\n%s: %b\n%s: %b\n%s: %b\n%s: %b\n\n",
 10:          "Conditional AND (&&)", "false && false", ( false && false ),
 11:          "false && true", ( false && true ), 
 12:          "true && false", ( true && false ),
 13:          "true && true", ( true && true ) );
 14: 
 15:       // create truth table for || (conditional OR) operator
 16:       System.out.printf( "%s\n%s: %b\n%s: %b\n%s: %b\n%s: %b\n\n",
 17:          "Conditional OR (||)", "false || false", ( false || false ),
 18:          "false || true", ( false || true ),
 19:          "true || false", ( true || false ),
 20:          "true || true", ( true || true ) );
 21: 
 22:       // create truth table for & (boolean logical AND) operator
 23:       System.out.printf( "%s\n%s: %b\n%s: %b\n%s: %b\n%s: %b\n\n",
 24:          "Boolean logical AND (&)", "false & false", ( false & false ),
 25:          "false & true", ( false & true ),
 26:          "true & false", ( true & false ),
 27:          "true & true", ( true & true ) );
 28: 
 29:       // create truth table for | (boolean logical inclusive OR) operator
 30:       System.out.printf( "%s\n%s: %b\n%s: %b\n%s: %b\n%s: %b\n\n",
 31:          "Boolean logical inclusive OR (|)",
 32:          "false | false", ( false | false ),
 33:          "false | true", ( false | true ),
 34:          "true | false", ( true | false ),
 35:          "true | true", ( true | true ) );
 36: 
 37:       // create truth table for ^ (boolean logical exclusive OR) operator
 38:       System.out.printf( "%s\n%s: %b\n%s: %b\n%s: %b\n%s: %b\n\n",
 39:          "Boolean logical exclusive OR (^)", 
 40:          "false ^ false", ( false ^ false ),
 41:          "false ^ true", ( false ^ true ),
 42:          "true ^ false", ( true ^ false ),
 43:          "true ^ true", ( true ^ true ) );
 44: 
 45:       // create truth table for ! (logical negation) operator
 46:       System.out.printf( "%s\n%s: %b\n%s: %b\n", "Logical NOT (!)",
 47:          "!false", ( !false ), "!true", ( !true ) );
 48:    } // end main
 49: } // end class LogicalOperators
 50: 
 51: 
 52: /**************************************************************************
 53:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 54:  * Pearson Education, Inc. All Rights Reserved.                           *
 55:  *                                                                        *
 56:  * DISCLAIMER: The authors and publisher of this book have used their     *
 57:  * best efforts in preparing the book. These efforts include the          *
 58:  * development, research, and testing of the theories and programs        *
 59:  * to determine their effectiveness. The authors and publisher make       *
 60:  * no warranty of any kind, expressed or implied, with regard to these    *
 61:  * programs or to the documentation contained in these books. The authors *
 62:  * and publisher shall not be liable in any event for incidental or       *
 63:  * consequential damages in connection with, or arising out of, the       *
 64:  * furnishing, performance, or use of these programs.                     *
 65:  *************************************************************************/