好吧,我试图读取一个看起来像这样的文本文件:
FTFFFTTFFTFT
3054 FTFFFTTFFTFT
4674 FTFTFFTTTFTF
......等
当我正在阅读它时,一切都编译并且工作得非常好,将所有内容放入这样的数组中:
studentID [0] = 3054
studentID [1] = 4674
......等
studentAnswers [0] = FTFFFTTFFTFT
studentAnswers [1] = FTFTFFTTTFTF
但是,如果studentID具有前导零或尾随零,当我使用System.out.println();打印它时,它会删除前导零和尾随零!我觉得这很简单,我需要复制数组或其他东西.谢谢 :)
以下是我的代码:
public static String[] getData() throws IOException {
int total = 0;
int[] studentID = new int[127];
String[] studentAnswers = new String[127];
String line = reader.readLine();
String answerKey = line;
StringTokenizer tokens;
while((line = reader.readLine()) != null) {
tokens = new StringTokenizer(line);
studentID[total] = Integer.parseInt(tokens.nextToken());
studentAnswers[total] = tokens.nextToken();
System.out.println(total + " " +studentID[total]); …
Run Code Online (Sandbox Code Playgroud) 我得到了这个家庭作业的问题,我能想到的只是返回一个抽象超类的子类.
谢谢!