Tracing Mutual Recursive Methods
What does the program print when executed?
public class MutualRecursion {
public static int a(int n) {
if (n <= 0) return 0;
return n - b(n-1);
}
public static int b(int n) {
if (n <= 0) return 0;
return n - a(n-1);
}
public static void main(String[] args) {
System.out.println(a(3));
}
}
A
3
B
2
C
0
D
1
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | lsj08030922 | 1 | 1 | 1m 15s | 25 |
| #3 | richa.tuli | 1 | 2 | 2m 33s | -63 |
APFIVE