Advertisement
veronikaaa86

06. Easter Competition

Feb 18th, 2023
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P06EasterCompetition {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int easterBreadCount = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int maxPoints = Integer.MIN_VALUE;
  12.         String winnerName = "";
  13.         for (int i = 1; i <= easterBreadCount; i++) {
  14.             String name = scanner.nextLine();
  15.  
  16.             int sumCurrentPoints = 0;
  17.             String input = scanner.nextLine();
  18.             while (!input.equals("Stop")) {
  19.                 int currentPoints = Integer.parseInt(input);
  20.  
  21.                 sumCurrentPoints = sumCurrentPoints + currentPoints;
  22.  
  23.                 input = scanner.nextLine();
  24.             }
  25.  
  26.             System.out.printf("%s has %d points.%n", name, sumCurrentPoints);
  27.  
  28.             if (sumCurrentPoints > maxPoints) {
  29.                 maxPoints = sumCurrentPoints;
  30.                 System.out.printf("%s is the new number 1!%n", name);
  31.                 winnerName = name;
  32.             }
  33.         }
  34.  
  35.         System.out.printf("%s won competition with %d points!%n", winnerName, maxPoints);
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement