desislava_topuzakova

06. Easter Competition

May 22nd, 2021
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PrintAndSum_04 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int countEasterBread = Integer.parseInt(scanner.nextLine());
  7.         int maxPoints = Integer.MIN_VALUE;
  8.         String bestChef = "";
  9.  
  10.         for (int easterBread = 1; easterBread <= countEasterBread; easterBread++) {
  11.             String chefName = scanner.nextLine();
  12.             int totalGrades = 0;
  13.             String command = scanner.nextLine(); //оценка или Stop
  14.             //стоп: command == "Stop" -> command != "Stop"
  15.             while(!command.equals("Stop")) {
  16.                 //оценка -> command = "10" -> 10
  17.                 int grade = Integer.parseInt(command);
  18.                 totalGrades += grade;
  19.                 command = scanner.nextLine();
  20.             }
  21.             System.out.printf("%s has %d points.%n", chefName, totalGrades);
  22.             //проверка дали този шеф е най-добрия
  23.             if(totalGrades > maxPoints) {
  24.                 maxPoints = totalGrades;
  25.                 bestChef = chefName;
  26.                 System.out.printf("%s is the new number 1!%n", bestChef);
  27.             }
  28.         }
  29.  
  30.         System.out.printf("%s won competition with %d points!%n", bestChef, maxPoints);
  31.  
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment