Recursive Sum Calculation
What is the output when the 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
0
C
3
D
Compilation Error
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE