Java~ Vector一問...

2006-10-31 2:56 am
有冇人可以explain呢段野係做d咩呀...呢一part我唔明佢要做d咩

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係咁:
更新1:

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);

更新2:

System.out.print(”Name: ”); nameStr = kb.nextLine(); while(!nameStr.equalsIgnoreCase(”quit”)) { myNameList.addElement(nameStr); System.out.print(”Name: ”); nameStr = kb.nextLine(); }

更新3:

System.out.println(”\nThe names list: ”); int i; int vectorSize = myNameList.size(); for (i = 0; i < vectorSize; i++) { System.out.println(myNameList.elementAt(i)); }

更新4:

System.out.println(”\nThe names list in alphabetical order: ”); Collections.sort(myNameList); System.out.println(myNameList);//(a,b,c,d)

更新5:

thx for helping me~

更新6:

仲有呢個係.. 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

回答 (2)

2006-10-31 8:09 am
✔ 最佳答案
以我理解, 你有一個name list, 而你段文字想你做的是, 將你有的name list 個sorting, 然後只print out 第一個name 個和最後一個name

eg. name list 有三人: Tom, Peter, John,
after sort, it should be John, Peter, Tom,
so you should print out John (First name) and Tom (Last name)
2006-11-03 5:53 pm
非常好


收錄日期: 2021-04-18 21:03:16
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061030000051KK04734

檢視 Wayback Machine 備份