Question: Create a class called Reverse that reverses an array of integers. The class should have two method: - public static void reverse(int [] array) Which

Create a class called Reverse that reverses an array of integers.

The class should have two method:

- public static void reverse(int [] array) Which calls the private recursive method, passing the array parameter and which two array elements should be swapped.

- private static void reverseRecursive(int [] array, int startIndex, int endIndex) Which swaps the two elements of the array parameter pointed to by the startIndex and endIndex parameters. The method should be called again, this time, with the startIndex incremented by one and the endIndex decremented by one.

The termination condition should occur when startIndex is equal to or greater than the endIndex, because this indicates all the elements in the array have been swapped.

Create a second class called ReverseTest that contains the main method, and tests the Reverse.reverse method. The method should be called twice, once with an array containing an odd number of elements, and once with an array containing an even number of elements. The test class does not need to ask for input from the user of the class, nor does it need to do any additional error checking.

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!