Compound Boolean Expressions

AP Computer Science A· difficulty 3/5

int x = 0;
int y = 5;
if (x != 0 && y / x > 1) {
  System.out.println("A");
} else {
  System.out.println("B");
}

What is printed?

  • A

    A

  • B

    B

    check_circle
  • C

    ArithmeticException

  • D

    nothing

Explanation

Short-circuit evaluation: x != 0 is false, so the && expression is false without evaluating y/x. No division by zero occurs. The else branch prints B.

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

Related questions