?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Arithmetic Operations: Math.random ArrayList of Ints

APCSA-XVT2FE

Consider the following method.

public static int processNums(ArrayList<Integer> nums)
{
    int a = 0;
    for (int i=0; i<nums.size(); i++)
    {
        a += nums.get((int) (Math.random()*nums.size()));
    }
    return a;
}

What are the possible values that could be output using the following code?

ArrayList<Integer> nums = new ArrayList<Integer>();
nums.add(400);
nums.add(300);
nums.add(200);
System.out.println(processNums(nums));
A

0, 1, or 2

B

0, 1, 2, 3, 4, 5, or 6

C

200, 300, or 400

D

600, 700, 800, 900, 1000, 1100, or 1200

E

1200