?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Adding Array Costs Using Double Data Type

APCSA-WGNJVY

Consider the following code segment.

double[] costs = {20.25, 100.75, 10.50, 35.01};
double sum = 0.0;

for (int i=0; i<costs.length; i++)
{
    if (costs[i] > 25)
        sum += (int) costs[i] - costs[i];
    else
        sum += (int) costs[i];
}
System.out.println(sum);

Which of the following numbers is closest to the number that will print to the console when the following segment of code is executed?

A

31.50

B

30.75

C

30.00

D

29.75

E

29.25