Problem Write Program Prompts User Enter Number Students Student S Name Score Finally Disp Q43867092
Problem: Write a program that prompts the user to enter thenumber of students and each student’s name and score, and finallydisplays the names of the students with the lowest andsecond-lowest scores.
Please edit my code! I have tried the it but everytime it onlydisplays this:
The student with the lowest score of 0 is null.
The student with the second lowest score of 0 is null.
My code:
import java.util.*;
public class Exercise05_09
{
public static void main(String[] args)
{
// Create a scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter the number ofstudents
System.out.println(“Please enter the number ofstudents: “);
int numStudents = input.nextInt();
int i = 0;
int lowestScore = 0;
String lowestScoreName = null;
int secondLowestScore = 0;
String secondLowestScoreName = null;
for (i = 0; i < numStudents; i++) {
System.out.println(“Please enterthe student’s name: “);
String studentName =input.next();
System.out.println(“Please enterthe student’s score: “);
int studentScore =input.nextInt();
// Find the two lowest score
while (studentScore <lowestScore) {
lowestScore =studentScore;
lowestScoreName= studentName;
while(secondLowestScore < studentScore && secondLowestScore> lowestScore) {
secondLowestScore = studentScore;
secondLowestScoreName = studentName;
}
numStudents++;
}
}
// Display the 2 lowest scores
System.out.println(“The student with the lowest scoreof ” + lowestScore + ” is ” + lowestScoreName + “.”);
System.out.println(“The student with the second lowestscore of ” + secondLowestScore + ” is ” + secondLowestScoreName +”.”);
}
}
Expert Answer
Answer to Problem: Write a program that prompts the user to enter the number of students and each student’s name and score, and fi…
OR