This is simple java exercise for beginners about string. The program sort the names in a given string.
Source Code
class SortString { public static void main(String args[]) { Stringstrings[]={"Naeem","Asad","Usman","Facebook","Twitter"}; String sort; for(int x=0;x<strings.length;x++) { for(int y=x+1;y<strings.length;y++) { if(strings[x].compareTo(strings[y])>0) { sort=strings[x]; strings[x]=strings[y]; strings[y]=sort; } } } System.out.println("Sorted Array of Strings:"); for(int z=0;z<strings.length;z++) System.out.println(strings[z]); } }
0 comments:
Post a Comment