Title

JAVA

      In this blog, you will find programs on JAVA and also some help on how to write programs for JAVA...

December 18, 2014

Bubble Sort

public class BSort
{
    public static void main()
    {
        int a[]={12,45,34,23,1,3,2,7,98};
        for(int x=0; x<a.length-1; x++)
        {
            for(int y=x+1; y<a.length; y++)
            {
                if(a[x] > a[y])
                {
                    int temp=a[y];
                    a[y]=a[x];
                    a[x]=temp;
                }
            }
        }
        for(int x=0; x<a.length; x++)
        {
            System.out.println(a[x]);
        }
    }
}

No comments:

Post a Comment

Please write your comment in the box below...