?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Compare Array Elements and Return Boolean Value

APCSA-J4MEDL

Consider the following method.

public static boolean compareArrayElements(int[] nums)
{
    for (int i=0; i<nums.length; i++)
    {
        if (nums[i] != nums[nums.length-i-1])
            return false;
    }
    return true;
}

Which of the following BEST describes the function of this method?

A

It returns true if the first element and last element are equal, and returns false otherwise.

B

It returns true if the nums array is symmetrical (same elements backwards and forwards) and returns false otherwise.

C

It returns true if the nums array is not symmetrical (does not contain the same elements backwards and forwards) and returns false otherwise.

D

It returns true if the nums array contains all the same values and returns false otherwise.

E

It returns true if the nums array does not contain all the same values and returns false otherwise.