?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Compare Each Pair of Elements in Array of Integers

APCSA-HW6TEY

Consider the following code segment.

int[] nums = {3, 4, 25, 20, 4, 4, 1, 3};

for (int i=0; i<nums.length; i+=2)
{
    if (nums[i] == nums[i+1])
        System.out.print(Math.pow(nums[i],2));
    else
    if (nums[i] < nums[i+1])
        System.out.print(Math.pow(nums[i+1], nums{i+1] - nums[i])));
    else
        System.out.print(Math.sqrt(nums[i])-nums[i+1]);
    System.out.print(" "); 
}

What is printed as a result of executing the code segment?

A
-1.0  160000  16.0  9.0
B
0.0  -20.0  16.0  9.0
C
4.0  -15.0  16.0  9.0
D
4.0  -20.0  16.0  9.0
E
An ArrayIndexOutOfBoundsException occurs.