Advertisement
stoyanoff

BestPlayer_05

Jul 19th, 2020
1,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BestPlayer_05 {
  4.     public static void main(String[] args) {
  5.         Scanner myScan = new Scanner(System.in);
  6.  
  7.         String input = "";
  8.         int goals = 0;
  9.  
  10.         int maxGoals = Integer.MIN_VALUE;
  11.         String bestPlayer = "";
  12.  
  13.         boolean isHatTrick = false;
  14.  
  15.         while (true) {
  16.             input = myScan.nextLine();
  17.             if (input.equals("END")) {
  18.                 break;
  19.             }
  20.             goals = Integer.parseInt(myScan.nextLine());
  21.  
  22.             if (goals == maxGoals) {
  23.                 continue;
  24.             }
  25.             if (goals > maxGoals) {
  26.                 maxGoals = goals;
  27.                 bestPlayer = input;
  28.             }
  29.             if (maxGoals >= 3) {
  30.                 isHatTrick = true;
  31.             }
  32.             if (maxGoals >= 10) {
  33.                 break;
  34.             }
  35.  
  36.  
  37.         }
  38.         System.out.printf("%s is the best player!%n", bestPlayer);
  39.         if (isHatTrick) {
  40.             System.out.printf("He has scored %d goals and made a hat-trick !!!", maxGoals);
  41.         } else {
  42.             System.out.printf("He has scored %d goals.", maxGoals);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement