?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Objects as Parameters in Method Calls

APCSA-SGT4S1

Given the following method:

public static ArrayList<Double> updatePercentages(ArrayList<Double> pcts)
{
    ArrayList<Double> percentsNoDecimals = pcts;
    for (int i=0; i<pcts.size(); i++)
    {
        pcts.set(i, pcts.get(i) * 100);
        percentsNoDecimals.set(i, pcts.get(i)*100);
    }
    return percentNoDecimals;
}

What prints to the console after the following segment of code is executed?

ArrayList<Double> percentages = new ArrayList<Double>();
percentages.add(.09);
percentages.add(.75);
percentages.add(.38);
percentages.add(1.00);

ArrayList<Double> newPercents = updatePercentages(percentages);
newPercents.set(0, 0.0);

System.out.println("percentages = " + percentages);
System.out.println("newPercents = " + newPercents);
A
percentages = [.09, .75, .38, 1.0]
newPercents = [0.0, 75.0, 38.0, 100.0]
B
percentages = [0.0, 7500.0, 3800.0, 10000.0]
newPercents = [0.0, 7500.0, 3800.0, 10000.0]
C
percentages = [9.0, 75.0, 38.0, 100.0]
newPercents = [0.0, 75.0, 38.0, 100.0]
D
percentages = [9.0, 75.0, 38.0, 100.0]
newPercents = [0.0, 7500.0, 3800.0, 10000.0]
E
percentages = [0.0, 75.0, 38.0, 100.0]
newPercents = [0.0, 75.0, 38.0, 100.0]