Recursive Sum Calculation
What is printed when the following program is executed?
public class RecursiveReturn {
public static int recursiveSum(int n) {
if(n <= 0) return 0;
Thread t = new Thread(() -> {});
t.start();
try {
t.join();
} catch(InterruptedException e) {
Thread.currentThread().interrupt();
}
return n + recursiveSum(n - 1);
}
public static void main(String[] args) {
System.out.println(recursiveSum(3));
}
}
A
6
B
3
C
Compilation Error
D
0
Question Leaderboard
Not enough data yet to show leaderboard.
