Question

Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1. Generate 11 random integer numbers between 1 and 100, and place each random number in a different element of a single-dimension array starting with the first number generated 2. Display the arrays contents in the order the numbers are initially Inserted. This is called an unsorted list. An example is below. Th The unsorted list is: 76 9e 86 66 32 78 30 74 375 3. Using the bubble sort, now sort the array from smallest integer to the largest. The bubble sort be in its own method; Use this code, and not some code you find online Bubble Sort Code: it cannot be in the main method. Here is the code for the bubble sort method public static void bubbleSoct(intL) list) int tempi for (int 1 t) temp 1ist[) 3 1) temp SLS 4. Display the arrays contents after the bubble sort is completed. An example is below The sorted list is3 32 37 6e 66 74 76 76 9
media%2F8ae%2F8ae84014-5291-4b08-95a4-55
0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Test{  

public static void main(String args[]){

int[] list = new int[11];

for(int i = 0; i < 11; i++)

list[i] = (int )(Math. random() * 100 + 1);

System.out.print("The unsorted list is: ");

for(int i = 0; i < list.length; i++)

System.out.print(list[i] + " ");

System.out.println("");

bubbleSort(list);

System.out.print("The sorted list is: ");

for(int i = 0; i < list.length; i++)

System.out.print(list[i] + " ");

System.out.println("");

double median;

int location;

location = list.length / 2;

median = list[location];

System.out.println("The median is located at position " + location + " and the value is " + median);

}

private static void bubbleSort(int[] list) {

int temp;

for(int i = list.length - 1; i > 0; i--) {

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

if(list[j] > list[j + 1]) {

temp = list[j];

list[j] = list[j + 1];

list[j + 1] = temp;

}

}

}

}

}

<terminated> Test [Java Applicationl C:AProgram FilesJava ire1.8.0 401 bin avaw. The unsorted list is: 23 79 61 93 92 84 69 33 75 43 85 The sorted list is: 23 33 43 61 69 75 79 84 85 92 93 The median is located at position 5 and the value is 75.0

Please check the code. If you have any doubts comment below and I am happy to help :)

Add a comment
Know the answer?
Add Answer to:
Write a Java program with a single-dimension array that holds 11 integer numbers and sort the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the bubble sort algorithm described here: While the array is not sorted For each adjacent...

    Implement the bubble sort algorithm described here: While the array is not sorted For each adjacent pair of elements If the pair is not sorted Swap the elements Use the BubbleSorter class to fill in the code and make it run with the BubbleSorterDemo class. BubbleSorter.java public class BubbleSorter {    /** Sort an integer array using the bubble sort algorithm. @param arr array of integers to sort    */    public static void sort(int[] arr)    { // Your...

  • JAVA PLEASE Using queues Radix sort Come up with an unsorted array of numbers (integer array)....

    JAVA PLEASE Using queues Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order.

  • in java Create an Eclipse Java project that utilize "Selection Sort" to sort an unsorted integer...

    in java Create an Eclipse Java project that utilize "Selection Sort" to sort an unsorted integer array of size 20 of random numbers in the range 0-500 inclusive. The main method should display the unsorted array and sorted array after Selection Sort.

  • I'm trying to code a C program so it sorts an array of integer numbers of...

    I'm trying to code a C program so it sorts an array of integer numbers of size n in ascending order. My code is written below but its not working properly, its giving me errors, I think my sort and swap functions aren't done right maybe, please help and fix. It says "undefined reference to "SelectionSort" as an error. But the question asks to not change the PrintArray and Main function. #include <stdio.h> void PrintArray(int size, int array[]) { for...

  • Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to...

    Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to easily plug-in new sort algorithms and compare them. Assume that input data is generated randomly and stored in a text file (have no less than 2000 items to sort). Do not restrict your program to only one data type, or to one ordering relationship. The data type, ordering relationship, and the sorting method must be input parameters for your program....

  • Written in Java Your job is to produce a program that sorts a list of numbers...

    Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...

  • Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and...

    Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and Insertion Sort. The numbers to be sorted will be obtained using a library function which generates pseudo-random numbers. TO Do 1. Fill an array with 140 real numbers between 0.00 and 945.00. Generate the numbers using the subroutine that generates random numbers. Make a spare copy of the array; you will need it later. 2. Call a subroutine to print the contents of the...

  • Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers...

    Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. USE THIS STUCTURE struct nodeQ{                            node *front;                            node *rear;               };               nodeQ que[10]; enqueue(que[i],data); EXAMPLE: Original, unsorted list: [170, 45, 75, 90, 2, 802, 24, 66] 1ST PASS:...

  • C programing Write a program to sort numbers in either descending or ascending order. The program...

    C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...

  • MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First...

    MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First ask the user how many elements of his/her array. 2) Then, read the integer array elements as input from the User. 3) Then, print out the array before the sorting 4) Apply Bubble sort algorithm on your array 5) Print out the array after the sorting 6) Print some welcome text to th user 7) Add comments to your code to describe how is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT