Limited access

Upgrade to access all content for this subject

The following method removes the element at index idx from the array and returns the resulting array without this element.

// Precondition: nums will contain at least 1 element
// Precondition: idx will be a valid index in nums
public static int[ ] removeFromArrayI(int[ ] nums, int idx)
{
     int[ ] temp = new int[nums.length-1];

     for (int i=0; i<idx; i++)
     {
         temp[i] = nums[i];
     }

     /* missing code */

     return temp;
}

Which of the following should replace /* missing code */ in this method in order to accomplish this task?

A
for (int i=idx; i<nums.length; i++)
{
    temp[i] = nums[i+1];
}
B
for (int i=idx; i<temp.length; i++)
{
    temp[i] = nums[i+1];
}
C
for (int i=idx; i<nums.length; i++)
{
    temp[i+1] = nums[i];
}
D
for (int i=idx; i<temp.length; i++)
{
    temp[i+1] = nums[i];
}
E
for (int i=idx+1; i<temp.length; i++)
{
    temp[i] = nums[i+1];
}
Select an assignment template