Java Reference
In-Depth Information
Figure 6
shows flowcharts for these examples.
Sometimes you need to invert a condition with the
!
(not) logical operator. For
example, we may want to carry out a certain action only if two strings are not equal:
if (!input.equals("S")) . . .
The
!
operator takes a single condition and evaluates to
true
if that condition is
false and to
false
if the condition is true.
206
207
Figure 6
Flowcharts for
&&
and
||
Combinations
Here is a summary of the three logical operations:
A&&B
A
B
true
true
true
true
false
false
false
false
Any
A
B
A
| |
B
true
true
Any
false
true
true
false
false
false