import java.util.*;
public class SortName{
public static void main(String[] argsv){
Scanner s = new Scanner(System.in);
System.out.print("How many data items do you wish to enter: ");
int num = new Integer(s.nextLine()).intValue();
String[] names = new String[num];
System.out.println();
int i = 0;
while(i <</SPAN> num){
names[i] = s.nextLine();
i++;
}
StringComparator strcomp = new StringComparator();
Arrays.sort(names, strcomp);
for (String name: names){
System.out.println(name);
}
}
}
class StringComparator implements Comparator<</SPAN>String>{
public int compare(String a, String b){
return a.compareTo(b);
}
} |
|