Recursive Method Output
What will be printed when the program runs?
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
Compilation Error
B
7
C
3
D
6
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE