这就是我所拥有的:
import java.util.*;
import java.text.*;
public class Lab4 {
public static void main(String[] args) {
Scanner s = new Scanner(System. in );
Scanner keyboard = new Scanner(System. in );
String input;
int students;
int correctAnswers = 0;
char[] answerKey = {
'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'A'
};
char[] userAnswers = new char[answerKey.length];
DecimalFormat df = new DecimalFormat("#0.0");
System.out.print("how many students are in your class?");
input = s.nextLine();
students = Integer.parseInt(input);
String[] name = new String[students];
for (int j = 0; j < students; ++j) {
System.out.print("Enter name of student " + (j + 1) + ": ");
name[j] = s.nextLine();
System.out.print("Enter quiz score answers :");
for (int k = 0; k < answerKey.length - 1; ++k) {
userAnswers[k] = s.next().charAt(0);
}
for (int i = 0; i < userAnswers.length; i++) {
if (userAnswers[i] == answerKey[i]) {
correctAnswers++;
}
}
System.out.println((df.format((correctAnswers / answerKey.length) * 100)) + "%");
}
}
}
但是每次我输入 12 个答案(甚至是正确的答案)时,它都会进入下一行并且不打印任何其他内容,我想知道它有什么问题,我想也许 userAnswers 没有正确分配?
无论如何,任何帮助将不胜感激。谢谢