gpt4 book ai didi

java - 如何从文件中读取一组字符并解释它

转载 作者:行者123 更新时间:2023-12-02 05:04:22 26 4
gpt4 key购买 nike

  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

谢谢

最佳答案

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

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

关于java - 如何从文件中读取一组字符并解释它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27928163/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com