public class  array{
  public static void main(String[] args){
    int num[] = {80,20,47,82,25,13};
    int l = num.length;
    int i,j;
    System.out.print("Given number : ");
    for (i = 0;i < l;i++ ){
      System.out.print("  " + num[i]);
    }
    System.out.println("\n");
    System.out.print("Accending order number : ");
    for (i = 0;i < l;i++ ){
    	//int temp=num[i];
    	 for (j = 0;j < l;j++ ){
    	if(num[i]>num[j])
    	{
    		num[i]=num[j];
    		
    	}
    }
    }
    for (i = 0;i < l;i++ ){
      System.out.print("  " + num[i]);
    }
    }
  }

output is coming wrong....

Given number : 80 20 47 82 25 13

Accending order number : 13 13 13 13 13 13

#
for (i = 0;i < l;i++ ){
#
//int temp=num[i];
#
for (j = 0;j < l;j++ ){
#
if(num[i]>num[j])
#
{
#
//num[i]=num[j];//wrong

int temp=num[j];
 num[j]=num[i];
  num[i]=temp;
#
 
#
}
#
}
#
}

or else simply use...

Arrays.sort(num);
Comments
very prompt...
for (i = 0;i< l;i++ )
    {
    	int temp=num[i];
    	 for (j = i;j<l;j++ )
    	 {
    		 if(num[i]>num[j])
    		 	{   			 
    			 	num[i]=num[j];
    			 	num[j]=temp;
    		   	}
    	 }
    }

Try this code

Edited 6 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

This question has already been answered. Start a new discussion instead.