if-else Statements

AP Computer Science A· difficulty 3/5

int n = 5;
if (n > 0)
  if (n > 10)
    System.out.println("big");
  else
    System.out.println("small");

What is printed?

  • A

    big

  • B

    small

    check_circle
  • C

    big small

  • D

    nothing

Explanation

The else binds to the nearest unmatched if (n > 10). Since n = 5, n > 0 is true (enter), n > 10 is false (else), so "small" prints.

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

Related questions