Recursive Method Output
What is printed when the following code segment is executed?
public class Test {
public static void main(String[] args) {
System.out.println(loop(3));
}
public static int loop(int n) {
if(n == 0)
return 0;
return n + loop(n-1);
}
}
A
6
B
3
C
7
D
Compilation Error
Question Leaderboard
Not enough data yet to show leaderboard.
