Advertisement
galinyotsev123

ProgBasicsExam28and29July2018-E05gameInfo

Dec 29th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E05gameInfo {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String team = scanner.nextLine();
  8. int n = Integer.parseInt(scanner.nextLine());
  9.  
  10. double sum = 0;
  11. int gamesWithAdditionalTime = 0;
  12. int gamesWithPenalties = 0;
  13. double averageMinutesPerGame = 0;
  14.  
  15. for (int i = 1; i <= n; i++) {
  16. int matchLength = Integer.parseInt(scanner.nextLine());
  17.  
  18. if (matchLength > 90 && matchLength <= 120){
  19. gamesWithAdditionalTime++;
  20. }
  21.  
  22.  
  23. else if (matchLength > 120){
  24. gamesWithPenalties++;
  25. }
  26. sum += matchLength;
  27. averageMinutesPerGame = sum / n;
  28.  
  29. }
  30.  
  31. System.out.printf("%s has played %.0f minutes. Average minutes per game: %.2f%n", team, sum, averageMinutesPerGame);
  32. System.out.printf("Games with penalties: %d%n", gamesWithPenalties);
  33. System.out.printf("Games with additional time: %d%n", gamesWithAdditionalTime);
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement