Recursive ArrayList Product
What is the output of the following program?
import java.util.*;
public class Main {
public static int recursiveProduct(ArrayList<Integer> list, int index) {
if(index >= list.size()) return 1;
return list.get(index) * recursiveProduct(list, index + 1);
}
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>(Arrays.asList(2, 3, 4));
System.out.println(recursiveProduct(list, 0));
}
}
A
18
B
24
C
12
D
20
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | bommasam000 | 1 | 1 | 0m 35s | 65 |
| #3 | singhris000 | 1 | 1 | 9m 02s | -442 |
Items per page:
10
1 – 3 of 3
APFIVE