Advertisement
Spocoman

Football Tournament

Sep 7th, 2024 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String team = scanner.nextLine(), result;
  7.         int matchCount = Integer.parseInt(scanner.nextLine()),
  8.                 won = 0, drawn = 0, lost = 0;
  9.  
  10.         for (int i = 0; i < matchCount; i++) {
  11.             result = scanner.nextLine();
  12.             if (result.equals("W")) {
  13.                 won++;
  14.             } else if (result.equals("D")) {
  15.                 drawn++;
  16.             } else {
  17.                 lost++;
  18.             }
  19.         }
  20.  
  21.         if (matchCount == 0) {
  22.             System.out.println(team + " hasn't played any games during this season.");
  23.         } else {
  24.             System.out.printf(
  25.                     """
  26.                            %s has won %d points during this season.
  27.                            Total stats:
  28.                            ## W: %d
  29.                            ## D: %d
  30.                            ## L: %d
  31.                            Win rate: %.2f%%
  32.                            """
  33.                     , team, won * 3 + drawn, won, drawn, lost, 100.0 * won / matchCount);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement