Code Editor

Let's look at a set of operators that let us use control flow in our programs. These operators are called Boolean operators.

There are three Boolean operators that we will explore. Let's start with the first one: and.

  1. The and operator is represented in Java by &&.
  2. It returns a boolean value of true only when the expressions on both sides of && are true.

For example, the code below shows one outcome of the Boolean operator &&:

// The following expression uses the "and" Boolean operator System.out.println(true && true); // prints true

The code below shows the rest of the possible outcomes of the Boolean operators: &&:

// The following expressions use the "and" Boolean operator System.out.println(false && false); // prints false System.out.println(false && true); // prints false System.out.println(true && false); // prints false

We can also use the Boolean operator && with Boolean expressions such as the following:

System.out.println(2 < 3 && 4 < 5);

The example above will print out true because the statements "2 is less than 3" and "4 is less than 5" are both true.

Report a Bug
If you see a bug or any other issue with this page, please report it here.