Recursion

AP Computer Science A· difficulty 4/5

public static void mystery(int n) {
    if (n <= 0) return;
    mystery(n - 1);
    System.out.print(n + " ");
}
mystery(3);

What is printed?

  • A

    1 2 3

    check_circle
  • B

    3 2 1

  • C

    0 1 2 3

  • D

    3 2 1 0

Explanation

The print happens AFTER the recursive call, so each value prints as the calls unwind, producing ascending output.

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

Related questions