-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBestPlayer.java
More file actions
49 lines (34 loc) · 1.27 KB
/
Copy pathBestPlayer.java
File metadata and controls
49 lines (34 loc) · 1.27 KB
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
44
45
46
47
48
49
package PBExams;
import java.util.Scanner;
public class BestPlayer {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int maxGoals = Integer.MIN_VALUE;
String lastPlayer = "";
boolean flag = false;
String namePlayer = scanner.nextLine();
while(!namePlayer.equals("END")){
int goals = Integer.parseInt(scanner.nextLine());
if(goals >= 10){
System.out.printf("%s is the best player!%n",namePlayer);
System.out.printf("He has scored %d goals and made a hat-trick !!!",goals);
flag = true;
break;
}
if(goals > maxGoals){
maxGoals = goals;
lastPlayer = namePlayer;
}
namePlayer = scanner.nextLine();
}
if(!flag) {
if (maxGoals >= 3) {
System.out.printf("%s is the best player!%n", lastPlayer);
System.out.printf("He has scored %d goals and made a hat-trick !!!", maxGoals);
} else {
System.out.printf("%s is the best player!%n", lastPlayer);
System.out.printf("He has scored %d goals.", maxGoals);
}
}
}
}