Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a method named, reverse, which reverses the order of an array's elements without creating another array. The header for the method, reverse, is: void
Write a method named, reverse, which reverses the order of an array's elements without creating another array. The header for the method, reverse, is: void reverse (int arr[]){... where arr is an array containing any number 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, FinalExam. In the 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 example below. Here are four tests you should run from the 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[] myArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}: int [] myArrayRev = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}: reverse (myArray): if (Arrays.equals (myArray, myArrRev)) System.out.println("reverse worked for 10 elements."): Pass an array with 9 elements and then verify the array elements are reversed upon returning from the method, reverse. Pass an array with 1 element and then verify the array element is unchanged upon returning from the method, reverse. Pass an array with 0 elements and then verify the array is unchanged reversed upon returning from the method, reverse
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started