+2 votes
in JAVA by
How to perform Bubble Sort in Java?

1 Answer

0 votes
by
Consider the following program to perform Bubble sort in Java.

public class BubbleSort {  

  public static void main(String[] args) {  

  int[] a = {10, 9, 7, 101, 23, 44, 12, 78, 34, 23};  

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

  {  

    for (int j=0;j<10;j++)  

    {  

      if(a[i]<a[j])  

      {  

        int temp = a[i];  

        a[i]=a[j];  

        a[j] = temp;   

      }  

    }  

  }  

  System.out.println("Printing Sorted List ...");  

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

  {  

    System.out.println(a[i]);  

  }  

}  

}  

Output:

Printing Sorted List . . .

7

9

10

12

23

34

34

44

78

101

Related questions

+2 votes
asked May 13, 2021 in JAVA by rajeshsharma
+1 vote
asked Mar 11, 2021 in JAVA by rajeshsharma
...