Question: JAVA- Write two public static methods in the U6_L4_Activity_Two class. The first should have the signature swap(int[] arr, int i, int j) and return type

JAVA-

Write two public static methods in the U6_L4_Activity_Two class. The first should have the signature swap(int[] arr, int i, int j) and return type void. This method should swap the values at the indices i and j of the array arr (precondition: i and j are both valid indices for arr).

The second method should have the signature allReverseSwap(int[] arr) and return type void. The method should swap the values of all the last elements with the beginning elements in the array, so that for example the array {1, 2, 3, 4, 5, 6} becomes {6, 5, 4, 3, 2, 1} after this method is called.

Hint: Use a for loop alongside the swap method to create the allReverseSwap method.

Use the runner class to test this method: do not add a main method to your code in the U6_L4_Activity_Two.java file or it will not be scored correctly.

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!