Compound Boolean Expressions

AP Computer Science A· difficulty 3/5

public static String check(int x, int y) {
    if (x != 0 && y / x > 1) return "yes";
    return "no";
}
// Call: System.out.println(check(0, 10));

What is printed?

  • A

    yes

  • B

    no

    check_circle
  • C

    ERROR

  • D

    ArithmeticException

Explanation

x!=0 is false; short-circuit prevents division by zero. Returns "no".

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

Related questions