if-else Statements

AP Computer Science A· difficulty 4/5

The <code>else</code> in <code>if (a) if (b) S1 else S2</code> binds to

  • A

    if (a)

  • B

    if (b) — the nearest unmatched if

    check_circle
  • C

    Both

  • D

    Neither

Explanation

"Dangling else" rule: matches the nearest preceding <code>if</code>.

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

Related questions