?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Summing the Numbers in an Integer Array

APCSA-CYVNWG

Which of the following methods will return the sum of all elements in the array that do not have a value between 1 and 10 (both inclusive)?

I.

public static int sumNumsI(int[ ] nums)    
{
    int sum=0;

    for (int i=0; i<nums.length; i++)
    {
        if (nums[i]>=1 && nums [i]<=10)
            sum +=nums[i];
    }
    return sum;
}

II.

public static int sumNumsII(int[] nums)
{
    int sum=0;

    for (int i=0; i<nums,length; i++)
    {
        if (nums[i]<1 || nums[i]>10 )
            sum+=nums[i];
    }
    return sum;
}

III.

public static int sumNumsIII(int[ ] nums)    
{
    int sum=0;

    for (int i=nums.length-1; i>0; i--)
    {
        if (nums[i]<1 || nums[i]>10)
            sum+=nums[i];
    }
    return sum;
}
A

I only

B

II only

C

III only

D

I and II only

E

II and III only