import java.util.*;
public class BubbleSort {
    private int x[],n;
    public BubbleSort(int n)
    {
        this.n=n;
        x=new int[n];
        Scanner src=new Scanner(System.in);
        for(int i=0;i<n;i++)
            x[i]=src.nextInt();
    }
    public void display()
    {
        for(int i=0;i<n;i++)
            System.out.print(x[i]+" ");
        System.out.println();
    }
    public void bubbleSort()
    {
        for(int i=0;i<n-1;i++)
            for(int j=0;j<n-1;j++)
                if(x[j]>x[j+1])
                {
                    int t=x[j];
                    x[j]=x[j+1];
                    x[j+1]=t;
                }
    }

}
class BubbleSortExp
{
    public static void main(String args[])
    {
        Scanner src=new Scanner(System.in);
        System.out.println("Enter the no of elements");
        int n=src.nextInt();
        System.out.println();
        System.out.println("The elements are :");
        BubbleSort obj=new BubbleSort(n);
        obj.bubbleSort();
        obj.display();
    }
}

O/P:

Enter the no of elements
10

The elements are :
12
23
88
65
42
13
99
81
9
78
The sorted elements are :
9 12 13 23 42 65 78 81 88 99 
BUILD SUCCESSFUL (total time: 23 seconds)
