コードについて簡単な質問があります。私はJavaにまったく慣れておらず、自己学習しようとしていますが、今はループにとらわれています。私には、これはうまくいくはずだと思います。問題は、生徒の数を求めすぎて、ユーザーに各生徒の名前とスコアを入力させることです。次に、スコアが1番目と2番目に高い生徒を表示する必要があります。何らかの理由で、私のコードは、最初に高いスコアと2番目に高いスコアの両方に入力した名とスコアを表示するだけです。私はおそらくいくつかの大きな間違いを犯しましたが、誰かが私を正しい方向に向けることができるかもしれませんか?これが巨大な混乱のように見える場合は申し訳ありません。:(
public class Chapter4_9 {
  public static void main(String[] args) {
    //scanner for input
    Scanner input = new Scanner(System.in);
    //ask user for number of students
    System.out.print("Enter the number of students: ");
    int numberStudents = input.nextInt();
    //declare variables
    double highestScore = 0;
    double tempScore = 0;
    double secondHighestScore = 0;
    String firstStudent = "";
    String tempStudent = "";
    String secondStudent = "";
    for (int i = 0; numberStudents != i; ++i) {
        System.out.print("Enter the students name followed by his score: ");
        String studentName = input.next();
        double studentScore = input.nextDouble();
        if (i == 0){
            firstStudent = studentName;
            highestScore = studentScore;
        }
        else if (studentScore > highestScore) {
            tempStudent = firstStudent;
            studentName = firstStudent;
            secondStudent = tempStudent;
            tempScore = highestScore;
            studentScore = highestScore;
            secondHighestScore = tempScore;
        }
    }   
    System.out.println("The highest scoring student is " + firstStudent + " with a " + highestScore);
    System.out.println("The second highest scoring student is " + secondStudent + " with a " + secondHighestScore);
}
}