Learn

The three Boolean operators &&, ||, and ! can also be used together and used multiple times to form larger Boolean expressions.

However, just like numerical operators, Boolean operators follow rules that specify the order in which they are evaluated. This order is called Boolean operator precedence.

The precedence of each Boolean operator is as follows:

  1. ! is evaluated first
  2. && is evaluated second
  3. || is evaluated third

Like numerical expressions, every expression within parentheses is evaluated first. Expressions are also read from left to right.

The following statement demonstrates how Boolean operator precedence works:

System.out.println( !(false) || true && false);

The example above will print out true. In order, the expression is evaluated as follows:

  1. First, the ! Boolean operator in !(false) returns true.
  2. Second, true && false evaluates to false.
  3. Finally, the remaining expression true || false evaluates to true.

Instructions

1.

Line 4 has a code statement that is incomplete. Use each Boolean operator no more than once to replace the empty comments /**/. The code statement should print out false.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?