I have a homework that only uses loops and selections. I do not know how to do it. Here is the topic:
Write a program that prompts the user to enter the number of students and each student's name, score. Finally, display two students have the highest scores.
Thank you.

8 Years
Discussion Span
Last Post by GDICommander

I know how to find the first highest, but can not find the second.

System.out.println("Enter a name of student: ");
            String namea=input.next();
            System.out.println("Enter a student score: ");
            double scorea = input.nextDouble();
System.out.println("Enter the number of student: ");
            int numberstudent=input.nextInt();

            for( int i=0;i<= numberstudent-1; i++)
                    System.out.println("Enter the student name: ");
                    String name1 =input.next();
                    System.out.println("Enter the student score: ");
                    double score1=input.nextDouble();
if (score1>scorea)
                    { namea=name1;

Edited by Reverend Jim: Fixed formatting


if (score1 > score of the greatest)
name of the second = name of the first
score of the second = score of the first
name of the first = new name of the first
score of the first = new score of the first

This is very easy to implement that pseudo-code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.