Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
hard Solved by 1 students

Recursive Method Output

Mark
< Prev
Next >

Consider the following class definition. What value is printed when the main method is executed?

public class Mystery {
    public static int mystery(int n) {
        if(n <= 2) {
            return n;
        }
        return mystery(n - 1) + mystery(n - 2) - mystery(n - 3);
    }
    public static void main(String[] args) {
        System.out.println(mystery(4));
    }
}
A

3

B

2

C

4

D

5

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|