public static int bad(int n) {
if (n == 0) return 0;
return n + bad(n + 1);
}
bad(1);What happens?
- Acheck_circle
StackOverflowError
- B
Returns 0
- C
Returns 1
- D
Compile-time error
Explanation
The recursive call goes AWAY from the base case (n+1 instead of n-1), causing infinite recursion and stack overflow.