Recursive Method Output
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
Question Leaderboard
Not enough data yet to show leaderboard.
