Advertisement
svephoto

Football League [Java]

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