Advertisement
damesova

Best Player - Java

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