Recursion

AP Computer Science A· difficulty 4/5

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

What is printed?

  • A

    3 2 1

    check_circle
  • B

    0 1 2 3

  • C

    3 2 1 0

  • D

    1 2 3

Explanation

The print happens BEFORE the recursive call, so values print from largest to smallest as the recursion descends.

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

Related questions