Question: Write a program that asks user for their input of number of elements to be sorted and then uses bubbleSort to sort them. BubbleSort is

Write a program that asks user for their input of number of elements to be sorted and then uses bubbleSort to sort them. BubbleSort is a sorting algorithm.

//Use Appropriate imports here.

public class bubbleSortArrayList {

public static void main(String[] args) {

ArrayList items = new ArrayList<>();

Scanner inp = new Scanner(System.in);

//Ask the user for how many elements to be added.

System.out.println("Enter the number of elements to be added");

int HowManyElements = inp.nextInt();

//Complete the for loop for adding the elements to the ArrayList.

for (int i = 1 ; i <=; i++){

}

//Print out the Original ArrayList after user input Here.

/* Call the non-static bubbleSort method using the instantiated object 'list' of the class it is defined */

list.bubbleSort(items);

}

/*Complete the BubbleSort Algorithm as per the ArrayList usage and methods. Remember, the way to access the index elements is different in arrayLists than in Arrays. */

public void bubbleSort (){

for (){

for (int i = 0; i < j ; i++){

if(){

int temp =;

;

;

}

}

}

//Print out the Sorted ArrayList Here.

}

}

}

Step by Step Solution

3.34 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer import javautilArrayList import javautilScanner public class Bub... View full answer

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 Operating System Questions!