public static void p(int n) {
if (n == 0) return;
System.out.print("A" + n + " ");
p(n - 1);
System.out.print("B" + n + " ");
}
p(2);What is printed?
- Acheck_circle
A2 A1 B1 B2
- B
A1 A2 B2 B1
- C
A2 B2 A1 B1
- D
B1 B2 A1 A2
Explanation
A2 prints, then call p(1) prints A1, then base case returns, then B1 prints, then B2.