Find us on Google+ Kill the code: String sorting in JAVA

Friday, 14 December 2012

String sorting in JAVA

ublic class string_sort {
        static String input[] = {"abcdefgh","abcdefg","abcdef","abcde","abcd","abcz","ab","bat", "basd", "ba", "bas","abcdefgh","abcdefg","abcdef","abcde","abcd","abcz","ab","bat", "basd", "ba", "bas"};
   
    static int max = input[0].length();
   
    public static void main(String args[]) {
        findMax();
        int[] all = {0,0};
        int k =0;
        int size = input.length;
            for(int i=0;i<size;i++) {
                for(int j=0;j<size;j++) {
                    if(input[i].compareTo(input[j]) < 0) {
                        swap(i,j);
                    }      
                }
            }
        for(int i=0;i<size;i++) {
            System.out.println("" + input[i]);
        }       
    }
static void swap(int i,int j) {
        String temp = "";
        temp = input[i];
        input[i] = input[j];
        input[j] = temp;
    }  
}

No comments:

Post a Comment