Fantastic! The final Boolean operator we will explore is called not.
- The not operator is represented in Java by
- It will return the opposite of the expression immediately after it. It will return
false if the expression is true, and
true if the expression is false.
The code below shows all the outcomes of the Boolean operator
We can also use the Boolean operator
! with Boolean expressions such as the following:
System.out.println( !(4 <= 10) );
The example above will print out
false because the statement "
4 is less than or equal to
10" is true, but the
! operator will return the opposite value, which is