Write a program that reads in 10 numbers from the user and stores them in a 1D array of size 10. Then, write BubbleSort to sort that array – continuously pushing the largest elements to the right side

Answers

Answer 1

Answer:

The solution is provided in the explanation section.

Detailed explanation is provided using comments within the code

Explanation:

import java.util.*;

public class Main {

//The Bubble sort method

public static void bb_Sort(int[] arr) {  

   int n = 10; //Length of array  

   int temp = 0; // create a temporal variable  

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

         for(int j=1; j < (n-i); j++){  

           if(arr[j-1] > arr[j]){  

               // The bubble sort algorithm swaps elements  

               temp = arr[j-1];  

               arr[j-1] = arr[j];  

               arr[j] = temp;  

             }  

         }            

         }  

        }

 public static void main(String[] args) {

   //declaring the array of integers

   int [] array = new int[10];

   //Prompt user to add elements into the array

   Scanner in = new Scanner(System.in);

   //Use for loop to receive all 10 elements

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

     System.out.println("Enter the next array Element");

     array[i] = in.nextInt();

   }

   //Print the array elements before bubble sort

   System.out.println("The Array before bubble sort");

   System.out.println(Arrays.toString(array));

   //Call bubble sort method

   bb_Sort(array);  

               

   System.out.println("Array After Bubble Sort");  

   System.out.println(Arrays.toString(array));

 }

}


Related Questions

Other Questions
A scientist studied bacteria.She placed 4 bacteria in a dish.The population of bacteria triples every 12 hoursWhich equation can be used to determine the number of bacteria, y, present after x days?O y = 4(3)xO y=4(6)xO y = 4(3) 2xO y = 4(6) 2x Anand needs to hire a plumber. He's considering a plumber that charges an initial fee of \$65$65dollar sign, 65 along with an hourly rate of \$28$28dollar sign, 28. The plumber only charges for a whole number of hours. Anand would like to spend no more than \$250$250dollar sign, 250, and he wonders how many hours of work he can afford. Let HHH represent the whole number of hours that the plumber works. Jim Crow laws were laws that- A- separated the sexesB- denied citizenship C-taxed voters D-separated the races How did the Bessemer process improve manufacturing? Which of the following was the African American killed in the Boston Massacre?(5 points)Samuel AdamsCrispus AttucksPaul RevereJohn Adams The fraction whose denominator is 8 more than the numarator Evaluate the following expression when x = -1, y = 2, z = -3, andw = 4.x - y How dependable is psychological information in popular media? It cost Samantha $4.23 to send 47 text messages. How much does each text cost to send? Please help brainiest!! What is the smallest unit ? How can you graphically tell if a quadratic equation will have a complex solution? Which of the following is not a formal power of the Governor?Group of answer choicesChief ExecutiveChief LegislatorChief of StateCommander-in-Chief How did climate change during the Mesolithic Era impact early peoples?O Sea levels receded, reducing the availability of fish as a food source.O Larger animals died out and smaller animals became the primary food source.O Conditions for growing crops improved, and farming became a reliable source of food.O Food shortages forced people to travel farther in search of animals to hunt. How are communities shaped by their surroundings PLEASE HELP!!! IF YOU GIT IT RIGHT I WILL GIVE YOU 90 BRANLY POINTS !!! Which of the following equations is not a proportion? 14/7 = 7/3.5, 1.5/3 = 3/9, 22/33 = 4/6, 2/3 = 142/213 Why should we be concerned about the disappearance of phytoplankton in the oceans Using these clues, make a quadilateral. Write the name and each side. What is the perimeter?1. rectangle with sides 7 feet2. 7feet3. 10 feet4. 10feet A carpenter has less than 120 minutes to spend painting furniture each day. Today, he has spent 30.5 minutes painting a desk. Now he will paint x chairs, each of which takes 12.5 minutes. What is the maximum number of chairs the carpenter can paint? Which of the following is NOT a characteristic of all living things?Ability to reproduceAbility to moveO Growth and developmentHomeostasis