【发布时间】:2015-06-08 09:48:47
【问题描述】:
我刚开始学习 Java,我正在努力完成这个练习。
我已经了解如何使用扫描仪从 txt 文件中提取信息(我认为)(我们只应该更改方法主体)。但是我不确定将信息传输到数组的正确语法。
我意识到它一定很简单,但我似乎无法弄清楚。有人可以在所需的语法和元素方面为我指出正确的方向吗?提前谢谢!
import java.util.Scanner;
import java.io.FileReader;
import java.io.IOException;
public class Lab02Task2 {
/**
* Loads the game records from a text file.
* A GameRecord array is constructed to store all the game records.
* The size of the GameRecord array should be the same as the number of non-empty records in the text file.
* The GameRecord array contains no null/empty entries.
*
* @param reader The java.io.Reader object that points to the text file to be read.
* @return A GameRecord array containing all the game records read from the text file.
*/
public GameRecord[] loadGameRecord(java.io.Reader reader) {
// write your code after this line
Scanner input = new Scanner(reader);
for (int i=0; input.hasNextLine(); i++) {
String inputRecord = input.nextLine();
input = new Scanner(inputRecord);
// array?
}
return null; // this line should be modified/removed after finishing the implementation of this method.
}
}
【问题讨论】:
标签: java arrays syntax java.util.scanner