1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anton [14]
3 years ago
13

Write a function in Java that takes in the int[] array, sorts it using bubble sort, then returns back the sorted array.

Computers and Technology
1 answer:
diamong [38]3 years ago
6 0
<h2>Answer </h2><h2></h2>

//Class to test the bubble sort

public class BubbleSortTest{

   

//Method to sort the array using bubbleSort

//Takes the array to be sorted as argument

public static int[] bubbleSort(int[] arr) {      

  //Create an integer to hold the length of the array

  int n = arr.length;  

   

  //Create a temporary variable to hold the values of the

                       //array

  //for swapping purposes. Initialize it to zero

  int temp = 0;  

   

  //Cycle through the array element by element

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

   

   //For each element

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

     

    //if the element is greater than the element after it

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

     //swap the elements  

     temp = arr[j-1];  

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

     arr[j] = temp;  

        }    //End of if        

   }   //End of inner for

    }   //End of outer for

 

 //return the sorted array

 return arr;

}

 

   //main method

    public static void main(String [] args){

  //create a sample array

        int [] myArray = {56, 23, 7, 4, 6};

   

  //Call the bubbleSort() method to sort the array

        int [] sortedArray = bubbleSort(myArray);

   

  //Print out the sorted array

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

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

        }

   

    } //End of main method

 

     

}  //End of class BubbleSortTest

<h2>Sample Output</h2>

4 6 7 23 56

<h2>Explanation:</h2>

The code above has been written in Java and it contains comments explaining necessary parts of the code. Please go through the comments. A sample output has also been provided.

For clarity, the following shows the actual function alone without using or including it in a class.

=========================================================

//Method to sort the array using bubbleSort

//Takes the array to be sorted as argument

public static int[] bubbleSort(int[] arr) {  

       

       //Create an integer to hold the length of the array

       int n = arr.length;  

       

       //Create a temporary variable to hold the values of the array

       //for swapping purposes. Initialize it to zero

       int temp = 0;  

       

       //Cycle through the array element by element

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

           

           //For each element

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

               

               //if the element is greater than the element after it

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

                   //swap the elements  

                   temp = arr[j-1];  

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

                   arr[j] = temp;  

            }  

                     

           }  

        }  

   

   //return the sorted array

   return arr;

}

=========================================================

You might be interested in
Which of the following is a hardware component used to hold the BitLocker encryption key and ensures encrypted data is not acces
Vadim26 [7]

Answer:

TPM(Trusted Platform Module) is the correct answer to the following question.

Explanation:

Because TPM is the computer chip which protects your system data and store all keys and access of data that is encrypted by these keys. So that's why TPM is that hardware component which is used to contain the encryption keys and that data is not accessible to any other person's whether your hard drive will be lost or stolen by anyone.

6 0
3 years ago
you have been using snmp on your network for monitoring and management. you are concerned about the security of this configurati
Zinaida [17]

The thing that should be done is to implement version 3 of SNMP.

<h3>How to depict the information?</h3>

In this situation, the person has been using snmp on your network for monitoring and management. you are concerned about the security of this configuration.

Therefore, since the person is concerned about the security of this configuration, the thing that should be done is to implement version 3 of SNMP.

Learn more about configuration on:

brainly.com/question/26084288

#SPJ12

6 0
1 year ago
Which layer of the OSI model provides a user interface in the form of an entry point for programs to access the network infrastr
Alexandra [31]

The OSI model layer that provides a user interface in the form of an entry point for software programs to access the network infrastructure is: application layer.

<h3>What is the OSI model?</h3>

OSI model is an acronym for open systems interconnection and it comprises seven (7) main layers, which typically starts from the hardware layers (layers in hardware systems) to the software layers (layers in software systems)

<h3>The layers of the OSI model</h3>

In Computer networking, the seven (7) layers of the OSI model include the following in sequential order;

  • Physical Layer
  • Data link Layer
  • Network Layer
  • Transport Layer
  • Session Layer
  • Presentation Layer
  • Application Layer

The uppermost layer of the OSI model which is the "application layer" gives software programs an access to the services that allow internet connection or network infrastructure.

Read more on OSI model here: brainly.com/question/14446612

3 0
2 years ago
List and briefly defined categories of security services.
Fynjy0 [20]
There are six categories of security services: authenticiation, access control, data confidentiality, data integrity, nonrepudiation, and availability service. First, is authentication service, which defines as the assurance that the communicator is legitimate and is the one that it claims to be. It can either be peer entity or data origin authentication. Second, access control which is to prevent any unauthorized uses of resources. After one is being authenticiated, then this service limit/controls who access? what accessing rights to the resources are allowed depending on the identified individuals. Data confifentiality: the protection of data from unauthorized disclosure. Data integrity: the assurance that data received are exactly as sent by an authorized entity (e.t.c, contain no modificafion, insertion, deletion, or replay).
7 0
3 years ago
You have two microservices that need to communicate with each other without holding up a thread on either end. One service will
Yakvenalex [24]

Answer: E. Use a RESTful architecture for both, send the ID through a POST, and ping the service with a GET until a response is available.

Explanation:

Since there are two microservices that need to communicate with each other without holding up a thread on either end, the communication framework should be used is a RESTful architecture for both, send the ID through a POST, and ping the service with a GET until a response is available.

REST is a software architectural style which is used in defining the set of rules that be used for the creation of web services. The REST architecture allows requesting systems to be able to access and manipulate web resources.

8 0
3 years ago
Other questions:
  • Which string method counts the number of characters in a string?
    5·1 answer
  • Match each task with the features necessary to complete the task
    10·1 answer
  • An advertiser who sells coffee beans adds the keyword "Java'" to an ad group. After two weeks, she runs a placement performance
    11·1 answer
  • Kenny FRIEND ME. Ps that is my brother
    9·2 answers
  • Hiiiiiiiiiiiiiiiiii <br>i'm new here!!!​
    14·2 answers
  • Lasses give programmers the ability to define their own types. <br><br> a. True<br> b. False
    10·1 answer
  • Which letter shows the ball when it has the maximum kinetic energy
    15·1 answer
  • Guys, please help me asap (Photo Attached) !!!!!!! HELP 25pts!!!!
    14·2 answers
  • SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SU
    6·2 answers
  • Self-driving cars are a result of developments in which field of computer<br> science?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!