| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice Test
Share
hard Solved by 3 students
Recursive Method Execution Trace
< Prev
Next >

What will be the output if the method coconut(5) is called?
Consider the following recursive method, where n is a positive integer.

public static void coconut(int n) {
  if (n > 0) {
    coconut(n - 1);
    System.out.print(n);
    coconut(n - 2);
  }
}

What will be the output if the method coconut(5) is called?

A

4321321

B

1234123121

C

123141251231

D

5432132121

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

APFIVE © 2020.
Email: [email protected]|Privacy Policy