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
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