1.WAJP
for sorting a given list of names in ascending order.
Program:
downlad link to namesort
class namesort {
String arr[]={"sarath","lahari","omkar","harsha","ram","mani"};
void sort(){
System.out.println("the given list");
for(int i=0;i<arr.length;i++) {
System.out.println(arr[i]);
}
System.out.println("After sorting");
for(int i=0;i<arr.length;i++) {
for(int j=0;j<arr.length;j++) {
if(arr[i].compareToIgnoreCase(arr[j])<0) {
String temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(int i=0;i<arr.length;i++) {
System.out.println(arr[i]);
}
return;
}
}
class sort {
public static void main(String args[]) {
namesort ns=new namesort();
ns.sort();
}
}
0 comments:
Post a Comment