Advertisement
veronikaaa86

05. PC Game Shop

Jun 24th, 2023
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04PCGameShop {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int hearthstoneCount = 0;
  12.         int forniteCount = 0;
  13.         int overwatchCount = 0;
  14.         int otherCount = 0;
  15.         for (int i = 1; i <= n; i++) {
  16.             String gameName = scanner.nextLine();
  17.  
  18.             switch (gameName) {
  19.                 case "Hearthstone":
  20.                     hearthstoneCount++;
  21.                     break;
  22.                 case "Fornite":
  23.                     forniteCount++;
  24.                     break;
  25.                 case "Overwatch":
  26.                     overwatchCount++;
  27.                     break;
  28.                 default:
  29.                     otherCount++;
  30.             }
  31.         }
  32.  
  33.         System.out.printf("Hearthstone - %.2f%%%n", hearthstoneCount * 1.0 / n * 100);
  34.         System.out.printf("Fornite - %.2f%%%n", forniteCount * 1.0 / n * 100);
  35.         System.out.printf("Overwatch - %.2f%%%n", overwatchCount * 1.0 / n * 100);
  36.         System.out.printf("Others - %.2f%%%n", otherCount * 1.0 / n * 100);
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement