这是我的java代码,用于比较MCQ答案和主函数中的答案关键字,学生的答案存储在外部.txt文件中。它确实显示了一个输出,但它不是正确的。下面是我的代码从外部文件读取二维数组
public static void main(String[] args)
{
char [] answer = new char[152];
//char[] answer = new char[10];
char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
int c = 0;
try{
Scanner data = new Scanner(new File("students1.txt"));
while(data.hasNextchar())
{
String s = data.nextLine();
int count = 0;
for(int i = 0; i< s.length(); i+=2) {
if(s.charAt(i) == keys[count])
count++;
}
System.out.println("Student " +c + "'s correct count is " + count);
c++;
}
}
catch(Exception e){
System.out.println(e);
}
In the Output Window it should show
Student 1's correct count is 7
Student 2's correct count is 7
Student 3's correct count is 7
Student 4's correct count is 6
Student 5's correct count is 5
Student 6's correct count is 4
Student 7's correct count is 8
Student 8's correct count is 7
什么是“正确的”?请编辑您的问题,包括文件 –
秒一个是正确的” – Priyanshu
提供的文件格式的.txt –