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
的内容谢谢
答案 0 :(得分:2)
您可以迭代字符串以查找Es的索引并计算金额。
int failures = 0;
for (int i = 0; i < secondLine.length(); i++)
{
char c = secondLine.charAt(i);
if (c == 'E') { failures++; }
...
}