desislava_topuzakova

05. Best Player

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