Advertisement
yovkovbpfps

EXAM 28-29 JULY 04.BEST PLAYER

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