-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathProblem$08.java
43 lines (34 loc) · 1.22 KB
/
Problem$08.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package chapter_five;
import java.util.Locale;
import java.util.Scanner;
/**
* 5.8 (Find the highest score) Write a program that prompts the user to enter the number
* of students and each student’s name and score, and finally displays the name of
* the student with the highest score. Use the next() method in the Scanner class
* to read a name, rather than using the nextLine() method.
*
* @author Sharaf Qeshta
* */
public class Problem$08
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in).useLocale(Locale.US);
System.out.print("enter the number of students: ");
int numberOfStudent = scanner.nextInt();
String maxName = ""; double maxScore = 0;
for (int i = 0; i < numberOfStudent; i++)
{
System.out.print("enter the name of the student: ");
String name = scanner.next();
System.out.print("enter " + name + " scores : ");
double scores = scanner.nextDouble();
if (scores > maxScore)
{
maxName = name;
maxScore = scores;
}
}
System.out.println(maxName + " have the highest score : " + maxScore);
}
}