Advertisement
mimisimi

Best player

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