| 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 4 students
Recursive Method Output
< Prev
Next >

What value is printed by the Mystery program?

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

2

B

4

C

5

D

3

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

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