Advertisement
Khamikaze

Untitled

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