Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BestPlayer_05 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String bestPlayer = "";
- int maxGoals = Integer.MIN_VALUE;
- //команда -> име на играч или "END"
- //stop: команда == "END"
- //continue: команда != "END"
- String command = scanner.nextLine();
- while (!command.equals("END")) {
- //command = име на играч
- String playerName = command;
- int goals = Integer.parseInt(scanner.nextLine());
- //проверка дали играчът ми е най-добър
- if (goals > maxGoals) {
- bestPlayer = playerName;
- maxGoals = goals;
- }
- //проверка за 10 гола
- if (goals >= 10) {
- break;
- }
- command = scanner.nextLine();
- }
- //името на най-добрия играч -> bestPlayer
- //броят голове от най-добрия играч -> maxGoals
- System.out.printf("%s is the best player!%n", bestPlayer);
- //проверка за хеттрик
- if (maxGoals >= 3) {
- System.out.printf("He has scored %d goals and made a hat-trick !!!", maxGoals);
- } else {
- System.out.printf("He has scored %d goals.", maxGoals);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment