Method named reverse Solution

Write a method named, reverse, which reverses the order of an array’s elements without creating another array. The header method, revese, is:

void reverse( int arr [] ) { ….

where arr is an array containing any of integer elements.

For example, if the array is (6, 4, 9, 1, 7) BEFORE calling reverse, then the array should be (7, 1, 9, 4, 6) AFTER

calling reverse. Your code should work for any length of integer array containing any values. Your reverse

method should not do any keyboard input and no printing to the console.

You should write the method, reverse, in a class named, FinaExam. In FinalExam class you must also

include a main method that tests the method, reverse. The main method may do console output, but does not

need any keyboard input. Arrays created in main for use in testing the reverse method should be created using

static initialization as in the exam* below. Here are four tests you run from be main method by calling

the reverse method:

Pass an array with 10 elements and then verify the array elements are reversed upon returning from the
method, reverse. Here is an example of doing this:

// create the array to test

int n “Array • C, 2, 3, 4, 5, 6,

int t I nyArrayRev • 9, 8, 7, 6, 5, 4,

reverse( nyArray

Arrays.equalsl “Array, nyArrRev ) )

Systen.out .println( -reverse worked

for el—ents.• ) ;

Pass an array with 9 ebrmnts and then verify be array elements Me reversed upon returning fr«n method,
Pass an array with 1 ebmnt and then verify array element is unchanged upon returning from the method,
Pass an array with O ebrmnts and then verify be array is unchanged reversed upon returning frm
method, reverse.
Powered by