Compound Boolean Expressions

AP Computer Science A· difficulty 2/5

int n = 50;
if (n >= 0 && n <= 100) {
  System.out.println("valid");
} else {
  System.out.println("invalid");
}

What is printed?

  • A

    valid

    check_circle
  • B

    0

  • C

    invalid

  • D

    100

Explanation

50 is between 0 and 100 inclusive, so both parts of the && are true, and "valid" is printed.

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

Related questions