Bubble Sort using ‘Java’

Positively! Bubble sort is a straightforward and wasteful arranging calculation that over and over strides through a rundown, looks at contiguous components, and trades them in the event that they are all mixed up. The calculation keeps on repeating through the rundown until no more trades are required, it is arranged to show that the rundown

Program

import java.util.Scanner;

class BubbleSort1{

 public static void main(String[] args)

 {

Scanner sc=new Scanner(System.in);

System.out.print("Enter No. of Elements: ");

int n=sc.nextInt();

int a[]=new int[n];

System.out.print("Enter "+n+" Elements: ");

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

a[i]=sc.nextInt();

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

{

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

{

if(a[j]<a[j-1])

{

int t=a[j];

a[j]=a[j-1];

a[j-1]=t;

}

}

}

System.out.print("Array After Bubble Sort is: ");

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

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

}

}

Output: