Advertisement
Spocoman

PC Game Shop

Sep 9th, 2024 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int games = Integer.parseInt(scanner.nextLine()),
  7.                 hearthstones = 0, fornites = 0, overwatches = 0, others = 0;
  8.         String game;
  9.  
  10.         for (int i = 0; i < games; i++) {
  11.             game = scanner.nextLine();
  12.             switch (game) {
  13.                 case "Hearthstone" -> hearthstones++;
  14.                 case "Fornite" -> fornites++;
  15.                 case "Overwatch" -> overwatches++;
  16.                 default -> others++;
  17.             }
  18.         }
  19.  
  20.         System.out.printf("Hearthstone - %.2f%%\n", 100.0 * hearthstones / games);
  21.         System.out.printf("Fornite - %.2f%%\n", 100.0 * fornites / games);
  22.         System.out.printf("Overwatch - %.2f%%\n", 100.0 * overwatches / games);
  23.         System.out.printf("Others - %.2f%%\n", 100.0 * others / games);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement