Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem: Write a program that prompts the user to enter the number of students and each student's name and score, and finally displays the names

Problem: Write a program that prompts the user to enter the number of students and each student's name and score, and finally displays the names of the students with the lowest and second-lowest scores.

Please edit my code! I have tried the it but everytime it only displays 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 of students System.out.println("Please enter the number of students: "); 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 enter the student's name: "); String studentName = input.next(); System.out.println("Please enter the 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 score of " + lowestScore + " is " + lowestScoreName + "."); System.out.println("The student with the second lowest score of " + secondLowestScore + " is " + secondLowestScoreName + "."); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago

Question

Explain methods of metal extraction with examples.

Answered: 1 week ago

Question

4-6 Is there a digital divide? If so, why does it matter?

Answered: 1 week ago