| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice Test
Share
medium Solved by 3 students
Recursive ArrayList Product
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy