嘿。您最近可能會看到我尋找幫助的帖子,但之前我做錯了,所以我要重新開始並從基礎開始。使用字符串標記器從文本文件中設置創建數組?
我想讀的文本文件看起來像這樣:
FTFFFTTFFTFT
3054 FTFFFTTFFTFT
4674 FTFTFFTTTFTF
...等
我需要做的是將第一行放入一個字符串中作爲答案。
接下來,我需要創建一個包含學生ID(第一個數字)的數組。 然後,我需要創建一個與包含學生答案的學生ID平行的數組。
下面是我的代碼,我不知道如何讓它像這樣工作,我想知道是否有人可以幫助我。
public static String[] getData() throws IOException {
int[] studentID = new int[50];
String[] studentAnswers = new String[50];
int total = 0;
String line = reader.readLine();
strTkn = new StringTokenizer(line);
String answerKey = strTkn.nextToken();
while(line != null) {
studentID[total] = Integer.parseInt(strTkn.nextToken());
studentAnswers[total] = strTkn.nextToken();
total++;
}
return studentAnswers;
}
所以在一天結束時,所述陣列結構應該是這樣的:
studentID [0] = 3054
studentID [1] = 4674
...等
studentAnswers [0] = FTFFFTTFFTFT
studentAnswers [1] = FTFTFFTTTFTF
謝謝:)