Question: import java.util.Arrays; public class Question2 { /* * TODO : You are asked to complete the method * rearranging. This method takes in as input

import java.util.Arrays;

public class Question2 {

/*

* TODO: You are asked to complete the method

* rearranging. This method takes in as input an

* array of ints and returns back nothing (void).

* You cannot change the function

* signature of this method. Your method question2 must call

* the swap method. Scroll down to find the swap method.

* You cannot use any kind of sorting to answer this question.

*/

public static void question2(int[] items)

{

}

/*

* TODO: You are asked to complete the method

* swap. This method takes in as input two ints

* and an array of ints. The int i and int j

* are the index i and index j in the array items.

* You are asked to swap the value at the index i in items

* with the value at the index j. You cannot change the function

* signature of this method. This method must be called inside question2.

*/

private static void swap(int i,int j,int[] items)

{

}

/*

* Do not write any code inside the main method and expect it to get marked.

* Any code that you write inside the main method will be ignored. However,

* you are free to edit the main function in any way you like for

* your own testing purposes.

*/

public static void main(String[] args) {

int [] items={-7,-3,20,10,8,2};

Question2.question2(items);

System.out.println(Arrays.toString(items)); //must print [-7, -3, 10, 8, 2, 20]

int [] items1={1,1,1,1,1,1,1,1};

Question2.question2(items1);

System.out.println(Arrays.toString(items1)); //must print [1, 1, 1, 1, 1, 1, 1, 1]

int [] items2={1,2,3,4,5,6,7,8,9};

Question2.question2(items2);

System.out.println(Arrays.toString(items2)); //must print [2, 3, 4, 5, 6, 7, 8, 9, 1]

int [] items3={6,7,8,0,1,2,3,-1,-2};

Question2.question2(items3);

System.out.println(Arrays.toString(items3)); //must print [-2, -1, 0, 1, 2, 3, 8, 7, 6]

int [] items4={0,0,0,0,1,2,3,-1,-2,-3};

Question2.question2(items4);

System.out.println(Arrays.toString(items4)); //must print [-3, -2, -1, 0, 0, 0, 0, 3, 2, 1]

int [] items5={-1,4,5,6,0,0,0,-2};

Question2.question2(items5);

System.out.println(Arrays.toString(items5)); //must print [-1, -2, 0, 0, 0, 6, 5, 4]

}

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!