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
kolbaska11 [484]
3 years ago
15

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

:
Computers and Technology
1 answer:
Vlad1618 [11]3 years ago
6 0

Answer:

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

       int n = arr.length;  

       int temp = 0;  

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

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

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

                                temp = arr[j-1];  

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

                                arr[j] = temp;  

                       }      

                }  

        }

        return arr;  

   }  

Explanation:

Above function is written in java language in which it takes integer array then sorts it using bubble sort and return back the array. The function has return type int[] which is necessary for returning array of type integer. The variable n contains the size of array which is calculated through  array's length method which is built in. Above function sorts array in descending order if you want to sort it in ascending order just change the condition of in if branch from <em>"</em><em>if(</em><em>arr[j-1] > arr[j]</em><em>)</em><em>"</em> to <em>"</em><em>if(</em><em>arr[j-1] < arr[j]</em><em>)</em><em>"</em> means replace > sign with < sign .

You might be interested in
Hoda wants to create a new presentation in PowerPoint with existing graphics and designs. What is the easiest and fastest way fo
Paul [167]

Answer: a

Explanation:

6 0
4 years ago
Taking phrases, sentences, or paragraphs of text from a source then using them without giving attribution is plagiarism. This in
lys-0071 [83]

Answer:

True, that would be plagiarism

8 0
3 years ago
Which of the following types of memory is used to load programs and transfer files during your work sessions? A. D-ROM B. RAM C.
hammer [34]
I believe the answer is B-Ram <span />
4 0
4 years ago
Read 2 more answers
Two technicians are discussing MAP sensors. Technician A says that the MAP sensor should be replaced if anything comes out of th
anygoal [31]

Answer:

Both are correct.

Explanation:

Both technicians are correct in this scenario. Technician A point of view is correct as well as technician B.

3 0
3 years ago
To create a DateTime object that represents a due date that's 90 days after the current date, you use the following code:
Helen [10]

If $due_date contains a DateTime object, $due_date_diff will contain  

c. a DateInterval object

Explanation:

  • The DateInterval class ¶  represents a date interval.
  • A date interval stores either a fixed amount of time (in years, months, days, hours etc) or a relative time string in the format that DateTime's constructor supports.
  • The diff method is just as easy to use, but provides an extra piece of information: total days. This is important because when using the DateTime object to find a difference, we have a source and destination date, and therefore we can reduce the units of time into larger denominations. However, having the total number of days in between is a valuable piece of information.
  • The PHP DateTime class has three methods that work with a DateInterval object:
  1. add
  2. sub
  3. diff

Properties

  • y  :Number of years.
  • m  :Number of months.
  • d  :Number of days.
  • h  :Number of hours.
  • i  :Number of minutes.
  • s  :Number of seconds.
4 0
3 years ago
Other questions:
  • In the INSERT statement that follows, assume that all of the table and column names are spelled correctly, that none of the colu
    9·1 answer
  • How to get 60 fps pubg​
    9·2 answers
  • If you delete a sent message on gmail does the person still get it
    14·1 answer
  • _______________ is the term for the convergence of real-time and non-real-time communications services such as telephony, instan
    11·1 answer
  • The ........ tag is used to create a link to another document​
    9·1 answer
  • This is in government
    15·1 answer
  • What three things in the third generation of computing helped get programming enthusiasts more involved with computers? Select 3
    12·2 answers
  • Being able to express your thoughts in an email is a primary technology skill. true or false.
    9·2 answers
  • A qualifier distinguishes the set of objects at the far end of the association based on the qualifier value.
    5·1 answer
  • Read the scenarios below, then use the drop-down menus to decide if you should use a database.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!