if ( fiber >= 4 || foam >= 3 ) System.out.println("House passes the code requirements!" ); else System.out.println("House fails." );
Here is what would happen if a house had 6 inches of fiberglass batting and 0 inches of plastic foam:
fiber >= 4 || foam >= 3 --------- --------- true false --------------- true
One true is enough.
|A||B||A && B||A || B|
AND is different from OR. Both of them combine Boolean values ( true/false values ) into one Boolean value. But each does this in a different way:
The operation of AND and OR can be displayed in a truth table.
In the table, A and B are operands.
They stand for true/false values or
expressions that yield true/false values.
For example, A could stand for a relational expression such
memory > 512 or a
string comparison like
phrase.equals( "quit" ).
Each row of the truth table shows how logical operators combine the true/false values of operands. For example, row one says that if A is false and B is false, then A && B is false also A || B is false.
Row three says that if A is true and B is false, then A && B is false also A || B is true.
All possible truth values of the operands A and B are listed in the left two columns. Each operand can take the value true or the value false, so there are four possible combinations of values for the two operands.