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:

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

Is the willingness to put a customer’s needs above ones own needs and to go beyond a job description to achieve customer satisfaction
What is computer virus?
Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline.
What are some of the common security weaknesses inherent in Unix or Linux based systems and what techniques can be used to harden these systems against an attack?
(5 pt.) The name of a variable in the C programming language is a string that can contain uppercase letters, lowercase letters, digits, or underscores. Furthermore, the first character in the string must be a letter, either uppercase or lowercase, or an underscore. If the name of a variable is determined by its first 8 characters, how many different variables can be named in C

Andre is finding working in an online group challenging because there are people in the group from many different cultural backgrounds. Which are the three major areas that present challenges to students in such situations?​

Answers

Answer:

When working in multicultural groups, students may find challenges in the areas of language barriers, social behavior expectations, and communication style differences.

Explanation:

Answer:

Different Communication Styles

Different Attitudes Toward Conflict

Different Approaches to Completing Tasks

Different Decision-Making Styles

Different Attitudes Toward Disclosure

Different Approaches to Knowing

Explanation:

6 things you should consider when planning a PowerPoint Presentation.

Answers

Answer: I would suggest you consider your audience and how you can connect to them. Is your presentation, well, presentable? Is whatever you're presenting reliable and true? Also, no more than 6 lines on each slide. Use colors that contrast and compliment. Images, use images. That pulls whoever you are presenting to more into your presentation.

Explanation:

How will you ensure that all of the network's applications and tcp/ip services also support ipv6?

Answers

Answer:

Configure the Extended BSD API socket.

Explanation:

There are two types of logical network address, they are IP version 4 and up version 6. They are used to route packets to various destinations from various sources.

A network application must configure this IP addresses protocol. The IP version4 is the default address applications use. To enable IP version 6 the extended BSD API is configured on the network.

Why is color theory important

Answers

The Importance of Color Theory in Painting. Color Theory was a required foundations course in the Visual Communication Design program at BYU, so all the design students took it–the interior designers, graphic designers, industrial designers, and the illustrators.
Hey, mate and thanks for letting me help you.

it helped the interior designers, graphic designers the industrial designers, and the illustrators. hope l helped have a good day.

Write a function named minMax() that accepts three integers arguments from the keyboard and finds the smallest and largest integers. Include the function minMax() in a working program. Make sure your function is called from main().Test the function by passing various combinations of three integers to it.

Answers

Answer:

public class Main

{

public static void main(String[] args) {

 minMax(1, 2, 3);

 minMax(100, 25, 33);

 minMax(11, 222, 37);

}

public static void minMax(int n1, int n2, int n3){

    int max, min;

    if(n1 >= n2 && n1 >= n3){

        max = n1;

    }

    else if(n2 >= n1 && n2 >= n3){

        max = n2;

    }

    else{

        max = n3;

    }

   

    if(n1 <= n2 && n1 <= n3){

        min = n1;

    }

    else if(n2 <= n1 && n2 <= n3){

        min = n2;

    }

    else{

        min = n3;

    }

    System.out.println("The max is " + max + "\nThe min is " + min);    

}

}

Explanation:

*The code is in Java.

Create a function named minMax() that takes three integers, n1, n2 and n3

Inside the function:

Declare the min and max

Check if n1 is greater than or equal to n2 and n3. If it is set it as max. If not, check if n2 is greater than or equal to n1 and n3. If it is set it as max. Otherwise, set n3 as max

Check if n1 is smaller than or equal to n2 and n3. If it is set it as min. If not, check if n2 is smaller than or equal to n1 and n3. If it is set it as min. Otherwise, set n3 as min

Print the max and min

Inside the main:

Call the minMax() with different combinations

Assume hosts A and B are each connected to a switch Svia 100-Mbps links. The propagation delay on each link is 25μs. The switch Sis a store-and-forward device and it requires a delay of 35μs to process a packet after is has received the last bit in the packet. Calculate the total time required to transmit 40,000 bits from Ato B in the following scenarios. (The total time is measured from the start of the transmission of the first bit at A, until the last bit is received at B. We always assume that links are bi-directional with the same transmission rate and propagation delay in each direction unless specifically instructed otherwise.)

Answers

Answer:

885 μs

Explanation:

Given that:

Switch via = 100 Mbps links

The propagation delay for each link = 25μs.

Retransmitting a received packet = 35μs

To determine:

The total time required to transmit 40,000 bits from A to B.

Considering the fact as a single packet:

Transmit Delay / link = size/bandwith

= 4×10⁴ bits / 100 × 10⁶ bits/sec

= 400 μs

The total transmission time = ( 2 × 400 + 2 × 25 + 35) μs

= (800 + 50 + 35) μs

= 885 μs

Other Questions