Recursive Method Output
What is printed when the following code is executed?
public class WeirdCalc {
public static int calc(int n) {
if(n == 1)
return 2;
return calc(n - 1) * 2 + 1;
}
public static void main(String[] args) {
System.out.println(calc(4));
}
}
A
23
B
22
C
21
D
24
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | sgarv2513 | 2 | 2 | 0m 00s | 200 |
| #2 | sailajavadlamani33 | 2 | 5 | 0m 00s | 170 |
| #3 | l.alzahrani04 | 1 | 1 | 0m 00s | 100 |
| #4 | waynechen0110 | 1 | 1 | 0m 00s | 100 |
| #5 | varunrajaram1 | 1 | 1 | 0m 00s | 100 |
| #6 | leftoverjluck | 1 | 1 | 0m 26s | 74 |
| #7 | adedokuntaiye006 | 1 | 1 | 0m 32s | 68 |
| #8 | alchemax043 | 1 | 1 | 1m 06s | 34 |
| #9 | y.seong2027 | 1 | 1 | 1m 45s | -5 |
| #10 | lsj08030922 | 1 | 1 | 2m 10s | -30 |
APFIVE