Question: Write the swapInArray() method described below. Write it in the SwapInArray class and don't modify the main() method. This method takes three inputs, a double[]

Write the swapInArray() method described below. Write it in the SwapInArray class and don't modify the main() method.

This method takes three inputs, a double[] array and two integer indexes. The method does not return anything. The method swaps the array elements at first and second array indexes. The array is changed after the call by having two elements moved.

As an example, assume double[] array = {1.1, 2.2, 3.3, 4.4, 5.5} and first = 1, second = 3. On output the array will have the values {1.1, 4.4, 3.3, 2.2, 5.5}

Write any additional Javadoc that's required.

import java.util.Arrays; /** Class to hold the helper method for swapping two elements in an array. */ public class SwapInArray { public SwapInArray (int[] arr, int l, int m, int r) { // TODO: Add the swapInArray() method. And add Javadoc for it. /** * Main method to provide test input to swapInArray(). * @param args ignored. */ public static void main(String[] args) { double[] array1 = {1.1, 2.2, 3.3, 4.4, 5.5}; System.out.println(Arrays.toString(array1)); swapInArray(array1, 1, 3); System.out.println(Arrays.toString(array1)); double[] array2 = {3.14, 1.59, 2.65, 3.58, 9.79, 3.23}; System.out.println(Arrays.toString(array2)); swapInArray(array2, 4, 0); System.out.println(Arrays.toString(array2)); } }

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!