Recursion

AP Computer Science A· difficulty 4/5

What does this print for n=4?

<code>void p(int n) { if (n == 0) return; System.out.print(n); p(n - 1); } </code></pre>

  • A

    4321

    check_circle
  • B

    0

  • C

    4

  • D

    1234

Explanation

Print n, then recursively p(n-1): 4, 3, 2, 1.

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

Related questions