Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PBMoreExercisesForLoop;
- import java.util.Scanner;
- public class FootballLeague {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int stadiumCapacity = Integer.parseInt(scanner.nextLine());
- int totalFans = Integer.parseInt(scanner.nextLine());
- int fansA = 0;
- int fansB = 0;
- int fansV = 0;
- int fansG = 0;
- for (int i = 1; i <= totalFans; i++) {
- String sector = scanner.nextLine();
- switch (sector) {
- case "A":
- fansA++;
- break;
- case "B":
- fansB ++;
- break;
- case "V":
- fansV++;
- break;
- case "G":
- fansG++;
- break;
- }
- }
- double fansAPercent = fansA * 1.0 * 100 / totalFans;
- double fansBPercent = fansB * 1.0 * 100 / totalFans;
- double fansVPercent = fansV * 1.0 * 100 / totalFans;
- double fansGPercent = fansG * 1.0 * 100 / totalFans;
- double totalFansPercent = totalFans * 1.0 * 100 / stadiumCapacity;
- System.out.printf("%.2f%%%n", fansAPercent);
- System.out.printf("%.2f%%%n", fansBPercent);
- System.out.printf("%.2f%%%n", fansVPercent);
- System.out.printf("%.2f%%%n", fansGPercent);
- System.out.printf("%.2f%%", totalFansPercent);
- }
- }
Add Comment
Please, Sign In to add comment