Compound Boolean Expressions

AP Computer Science A· difficulty 2/5

int n = 7;
if (n < 0 || n > 10) {
  System.out.println("out");
} else {
  System.out.println("in");
}

What is printed?

  • A

    out

  • B

    nothing

  • C

    in

    check_circle
  • D

    out in

Explanation

n = 7 is not less than 0, and not greater than 10. Both parts of the || are false, so the else branch prints "in".

Want 10 more like this — adaptive to your weak spots?

Related questions