TZinovieva

Football League Футболен турнир 100/100

Apr 15th, 2022 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. package PBMoreExercisesForLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FootballLeague {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int stadiumCapacity = Integer.parseInt(scanner.nextLine());
  10.         int totalFans = Integer.parseInt(scanner.nextLine());
  11.  
  12.  
  13.         int fansA = 0;
  14.         int fansB = 0;
  15.         int fansV = 0;
  16.         int fansG = 0;
  17.  
  18.  
  19.         for (int i = 1; i <= totalFans; i++) {
  20.             String sector = scanner.nextLine();
  21.             switch (sector) {
  22.                 case "A":
  23.                     fansA++;
  24.                     break;
  25.                 case "B":
  26.                     fansB ++;
  27.                     break;
  28.                 case "V":
  29.                     fansV++;
  30.                     break;
  31.                 case "G":
  32.                     fansG++;
  33.                     break;
  34.             }
  35.         }
  36.             double fansAPercent = fansA * 1.0 * 100 / totalFans;
  37.             double fansBPercent = fansB * 1.0 * 100 / totalFans;
  38.             double fansVPercent = fansV * 1.0 * 100 / totalFans;
  39.             double fansGPercent = fansG * 1.0 * 100 / totalFans;
  40.  
  41.             double totalFansPercent =  totalFans * 1.0 * 100 / stadiumCapacity;
  42.  
  43.             System.out.printf("%.2f%%%n", fansAPercent);
  44.             System.out.printf("%.2f%%%n", fansBPercent);
  45.             System.out.printf("%.2f%%%n", fansVPercent);
  46.             System.out.printf("%.2f%%%n", fansGPercent);
  47.             System.out.printf("%.2f%%", totalFansPercent);
  48.  
  49.         }
  50.     }
  51.  
Add Comment
Please, Sign In to add comment