Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
hard Solved by 3 students

Tracing a Recursive Method

Mark
< Prev
Next >

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

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

2

B

0

C

3

D

1

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1nabihamanahal22 - 200
#2raufyildirim9511 0m 46s 54
#3hiboyshello01 - -10
Items per page:
10
1 – 3 of 3
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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