這是我的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 –