Tracing Mutual Recursive Methods
What is the output of the following program?
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
0
C
1
D
2
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | parth.taur227 | 2 | 2 | 2m 30s | 50 |
| #3 | lsj08030922 | 1 | 1 | 1m 15s | 25 |
| #4 | richa.tuli | 1 | 2 | 2m 33s | -63 |
| #5 | bommasam000 | 1 | 1 | 2m 56s | -76 |
| #6 | chunxiangxu.cxu | 0 | 1 | 8m 10s | -500 |
| #7 | liuwilliam072410 | 1 | 2 | 2h 20m | -8,359 |
Items per page:
10
1 – 7 of 7
APFIVE