desislava_topuzakova

05.Best Player

Jul 17th, 2021
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BestPlayer_05 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String bestPlayer = "";
  7.         int maxGoals = Integer.MIN_VALUE;
  8.         //команда -> име на играч или "END"
  9.         //stop: команда == "END"
  10.         //continue: команда != "END"
  11.         String command = scanner.nextLine();
  12.         while (!command.equals("END")) {
  13.             //command = име на играч
  14.             String playerName = command;
  15.             int goals = Integer.parseInt(scanner.nextLine());
  16.  
  17.             //проверка дали играчът ми е най-добър
  18.             if (goals > maxGoals) {
  19.                 bestPlayer = playerName;
  20.                 maxGoals = goals;
  21.             }
  22.  
  23.             //проверка за 10 гола
  24.             if (goals >= 10) {
  25.                 break;
  26.             }
  27.  
  28.             command = scanner.nextLine();
  29.         }
  30.  
  31.         //името на най-добрия играч -> bestPlayer
  32.         //броят голове от най-добрия играч -> maxGoals
  33.         System.out.printf("%s is the best player!%n", bestPlayer);
  34.         //проверка за хеттрик
  35.         if (maxGoals >= 3) {
  36.             System.out.printf("He has scored %d goals and made a hat-trick !!!", maxGoals);
  37.         } else {
  38.             System.out.printf("He has scored %d goals.", maxGoals);
  39.         }
  40.  
  41.  
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment