Great! The second Boolean operator that we will explore is called or.
- The or operator is represented in Java by
- It returns a Boolean value of
true when at least one expression on either side of
|| is true.
The code below shows all the outcomes of the Boolean operator
System.out.println(false || false);
System.out.println(false || true);
System.out.println(true || false);
System.out.println(true || true);
We can also use the Boolean operator
|| with Boolean expressions such as the following:
System.out.println(2 > 1 || 3 > 4);
The example above will print out
true because at least one statement — "
2 is greater than
1" — is true even though the other statement — "
3 is greater than
4" — is false.