小编ash*_*ion的帖子

为什么我的数组会从我正在阅读的文件中删除零?

好吧,我试图读取一个看起来像这样的文本文件:

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)

java arrays

5
推荐指数
1
解决办法
162
查看次数

为什么不是所有Java类都有接口?

我有这个问题要做作业,我不知道如何回答.你能救我吗?

java interface class

3
推荐指数
1
解决办法
514
查看次数

在类中可能包含静态方法的3种可能情况是什么?

我得到了这个家庭作业的问题,我能想到的只是返回一个抽象超类的子类.

谢谢!

java methods static class

2
推荐指数
1
解决办法
975
查看次数

标签 统计

java ×3

class ×2

arrays ×1

interface ×1

methods ×1

static ×1