Sunday, September 12, 2010

Sorting an Array

Hello programmers.. my students.. i want to create a program in java that sort a number in descending order.

here is a sample program...
public class Sorting
{
    public static void main(String args[])
    {
        int arr[]={0,1,2,3,4,5,6,7,8,9,10};
        int temp=0;
       
        for(int i=0; i<10;i++)
        {
            for(int j=0; j<10; j++)
            {
                if(arr[j]
                {
                    temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
       
        for(int x=0; x<10; x++)
        {
            System.out.println(arr[x]+ " ");
        }
    }
}


i hope you learn more in my blog,.... Think it Code it

No comments:

Post a Comment