| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
medium Solved by 5 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

24

C

12

D

20

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki11 0m 00s 100
#2bommasam00011 0m 35s 65
#3singhris00011 9m 02s -442
Items per page:
10
1 – 3 of 3
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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