Sunday, 20 March 2016

Sorting numbers



class SortString{
 static String arr[]={
"13com50","13com48","13com64","13com41","13com52",
     "13com38","13com55","13com64","13com36","13com57"
                 
                      };
     public static void main(String args[]) {
               for(int j=0;j<arr.length;j++){
                for (int i=j+1;i<arr.length;i++) {
                 if(arr[i].compareTo(arr[j])<0) {
       String t=arr[j];
       arr[j]=arr[i];
       arr[i]=t;
      }
    }
  }
System.out.println("NAMES IN ASCENDING ORDER");
        for(int k =0; k<arr.length; k++)
      System.out.println(arr[k]);

System.out.println("NAMES IN DECENDING ORDER");
for(int k = arr.length-1;k>=0;k--)
            System.out.println(arr[k]);
   }
}
 
 OUTPUT:                                                                                                                   

H:\>javac ascendingorder.java
H:\>java SortString
NAMES IN ASCENDING ORDER
13com36
13com38
13com41
13com48
13com50
13com52
13com55
13com57
13com64
13com64
NAMES IN DECENDING ORDER
13com64
13com64
13com57
13com55
13com52
13com50
13com48
13com41
13com38
13com36



No comments:

Post a Comment