Sponsored Links

November 23, 2017

Program to sort numbers

class Sorting{
 public static void main(String args[]){
  int number[]={55,40,70,80,90,21};
  int n = number.length;
                System.out.print("Given list:");
                for (int i=0;i<n;i++)
                {
                    System.out.print("\t"+number[i]);
                }
                System.out.println("\n");
            //Sorting begins
                for(int i=0;i<n;i++){
                    for (int j=i+1;j<n;j++){
                        if (number[i]<number[j]){
                            //interchange values
                               int temp=number[i];
                               number[i]=number[j];
                               number[j]=temp;
                        }
                    }
                }
                System.out.print("Sorted list:");
                for(int i=0;i<n;i++){
                    System.out.print("\t"+number[i]);
                    
                }
 }

No comments:

Post a Comment