Java Reference
In-Depth Information
Table 3.2
The Truth Table for the or Operator
OR
TRUE
FALSE
TRUE
TRUE
TRUE
FALSE
TRUE
FALSE
The exclusive or Operator
The exclusive or operator is used when you want a combined Boolean expres-
sion to be true only when exactly one of the two statements is true. Table 3.3
shows the truth table for the exclusive or operator.
For example, a Boolean expression of the form true exclusive or false is true,
while true exclusive or true is false.
The not Operator
The final Boolean operator I want to discuss is the not operator, which negates
a single Boolean expression. If I say something that was not true, it must be
false. Similarly, if I say something that is not false, it must be true. The not
operator performs this logic in your code.
There is no truth table for the not operator because it is only performed
on a single expression.
Consider the following statement:
Not (it is raining out today).
This example may not sound grammatically correct, but it is programmati-
cally correct. The not operator is placed at the beginning of a Boolean expres-
sion. The statement above is true when it is not raining out today. If it is raining
out today, the statement is false.
Table 3.3
The Truth Table for the exclusive or Operator
EXCLUSIVE OR
TRUE
FALSE
TRUE
FALSE
TRUE
FALSE
TRUE
FALSE
Search WWH ::




Custom Search