如何从文件中读取一组字符并对其进行解释

时间:2015-01-13 17:40:09

标签: java

  switch (secondLine) {
                    case "EEEEEEEEEEEE":
                        System.out.println("12 mistakes");
                        break;
                    case "............":
                        System.out.println("All test passed");
                        break;
                    //If a student fails 1-11 then check the file for the thirdLastLine and return the integer
                    default:

                        System.out.println("You failed some test and here is your result: " + secondLine);

                        break;

我希望能够指出E和失败以及字符集中的确切位置。编译器会返回类似E..E .... E..E

的内容

谢谢

1 个答案:

答案 0 :(得分:2)

您可以迭代字符串以查找Es的索引并计算金额。

int failures = 0;
for (int i = 0; i < secondLine.length(); i++)
{
    char c = secondLine.charAt(i);
    if (c == 'E') { failures++; }
    ...
}