Advertisement
Ivakis

Untitled

Oct 14th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int stadiumCapacity = Integer.parseInt(scanner.nextLine());
  8. int fansCount = Integer.parseInt(scanner.nextLine());
  9.  
  10. double sectorA = 0;
  11. double sectorB = 0;
  12. double sectorV = 0;
  13. double sectorG = 0;
  14.  
  15. for (int i = 0; i < fansCount; i++) {
  16. char sector = scanner.nextLine().charAt(0);
  17.  
  18. if(sector == 'A'){
  19. sectorA++;
  20. }else if(sector == 'B'){
  21. sectorB++;
  22. }else if(sector == 'V'){
  23. sectorV++;
  24. }else if(sector == 'G'){
  25. sectorG++;
  26. }
  27. }
  28.  
  29. double sectorAPercentage = sectorA / fansCount * 100;
  30. double sectorBPercentage = sectorB / fansCount * 100;
  31. double sectorVPercentage = sectorV / fansCount * 100;
  32. double sectorGPercentage = sectorG / fansCount * 100;
  33.  
  34. double stadiumPercentage = (double)fansCount / stadiumCapacity * 100;
  35.  
  36. System.out.printf("%.2f%%%n",sectorAPercentage);
  37. System.out.printf("%.2f%%%n",sectorBPercentage);
  38. System.out.printf("%.2f%%%n",sectorVPercentage);
  39. System.out.printf("%.2f%%%n",sectorGPercentage);
  40. System.out.printf("%.2f%%%n",stadiumPercentage);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement