Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the Java procedure reverseArray: /* reverseArray ( int[] ) procedure rever

ID: 3764574 • Letter: W

Question

Write the Java procedure reverseArray:

/*
reverseArray ( int[] )
  
procedure reverses the order of the given integer array
  
ex1: when reverseArray( {1, 2, 3, 4, 5} ) returns,
the array argument is {5, 4, 3, 2, 1}
ex2: when reverseArray( {} ) returns, the array argument is unchanged
ex3: when reverseArray( {1} ) returns, the array argument is unchanged
*/

Hint: Swap pairs of integers, beginning at the ends of the array and working toward the center. If the array contains an odd number of integers, the middle integer does not move.

Explanation / Answer

public static int[] reverse(int[] x) { int []d = new int[x.length]; for (int i = 0; i