add to your program so that it finds and prints out the first string (first name) and the last string (last name) according to dictionary order (strings with the smallest value and the largest value are to be printed)
我做左既其他part係咁:
main {Vector myNameList = new Vector (10); System.out.println(”Please enter the list of names. ”); System.out.println(”Use ’quit’ to finish.\n”); String nameStr; Scanner kb = new Scanner(System.in);
System.out.print(”Name: ”); nameStr = kb.nextLine(); while(!nameStr.equalsIgnoreCase(”quit”)) { myNameList.addElement(nameStr); System.out.print(”Name: ”); nameStr = kb.nextLine(); }
System.out.println(”\nThe names list: ”); int i; int vectorSize = myNameList.size(); for (i = 0; i < vectorSize; i++) { System.out.println(myNameList.elementAt(i)); }
System.out.println(”\nThe names list in alphabetical order: ”); Collections.sort(myNameList); System.out.println(myNameList);//(a,b,c,d)
thx for helping me~
仲有呢個係.. import java.util.Vector;//Vector class for 1.5jdk import java.util.Scanner;//Scanner class for 1.5jdk import java.util.Collections;//Collections class for 1.5jdk public class VectorClass { public static void main (String [] args) { ... }//end main }//end class