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
20
C
12
D
24
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE