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.

Recommended Answers

All 3 Replies

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;
                      scorea=score1;
                    }

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.