Write a program that prompts the user to enter the number of students and each s
ID: 642927 • Letter: W
Question
Write a program that prompts the user to enter the number of students and each student
Explanation / Answer
import java.util.Scanner; public class Exercise09 { public static void main(String[] args) { System.out.print("Enter the number of students: "); Scanner input = new Scanner(System.in); int numberOfStudents = input.nextInt(); if (numberOfStudents > 1 ) { System.out.print("Enter student's name: "); String highestStudentsName = input.next(); System.out.print("Enter student's score: "); int highestStudentsScore = input.nextInt(); System.out.print("Enter student's name: "); String highStudentsName = input.next(); System.out.print("Enter student's score: "); int highStudentsScore = input.nextInt(); if (highestStudentsScore highestStudentsScore) { int tmpScore = highestStudentsScore; String tmpName = highestStudentsName; highestStudentsScore = StudentsScore; highestStudentsName = StudentsName; if (tmpScore > highStudentsScore) { highStudentsScore = tmpScore; highStudentsName = tmpName; } } else { highStudentsScore = StudentsScore; highStudentsName = StudentsName; } } } input.close(); System.out.println(highestStudentsName + " - " + highestStudentsScore); System.out.println(highStudentsName + " - " + highStudentsScore); } else { System.out.println("The number of students must be greater than 1"); } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.