Question: Consider the following method, which is intended to return an array of integers that contains the elements of the parameter arr arranged in reverse order.

Consider the following method, which is intended to return an array of integers that contains the elements of the parameter arr arranged in reverse order. For example, if arr contains {7,2,3,-5}, then a new array containing {-5,3,2,7} should be returned and the parameter arr should be left unchanged.
public static int[] reverse(int[] arr)
{
int[] newArr = new int[arr.length];
for (int k =0; k < arr.length; k++)
{
/* missing statement */
}
return newArr;
}
Which of the following statements can be used to replace /* missing statement */ so that the method works as intended?
Responses
newArray[k]= arr[-k];
newArray[k]= arr[-k];
newArray[k]= arr[k - arr.length];
newArray[k]= arr[k - arr.length];
newArray[k]= arr[k - arr.length -1];
newArray[k]= arr[k - arr.length -1];
newArray[k]= arr[arr.length - k];
newArray[k]= arr[arr.length - k];
newArray[k]= arr[arr.length - k -1];

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!