package ltb6w1; public class WordSort1 { private String[] a= {"hello","world","welcome","hi","hey"};
private int w;
private int q; public WordSort1() { for(int i=0;i<a.length-1;i++) { for(int j=i+1;j<a.length;j++) { if(a[i].compareTo(a[j])>0) { w=i;
q=j; getWordSort(a[i],a[j]); } }
}
} public void getWordSort(String ai,String aj) { String temp;
temp=ai;
a[w]=aj;
a[q]=temp; } public void printSort() { for(String s:a) { System.out.print(s+" ");
}
}
public static void main(String[] args) { WordSort1 ws=new WordSort1();
ws.printSort();
} }