Advertisement
CR7CR7

forAsq

Feb 21st, 2023
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class taskPCSells {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int gamesSold = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int hearthstone = 0;
  10.         int fornite = 0;
  11.         int overwatch = 0;
  12.         int others = 0;
  13.  
  14.         for (int i = 1; i <= gamesSold ; i++) {
  15.             String game = scanner.nextLine();
  16.             if(game.equals("Hearthstone")){
  17.                 hearthstone++;
  18.             }else if (game.equals("Fornite")){
  19.                 fornite++;
  20.             }else if (game.equals("Overwatch")){
  21.                 overwatch++;
  22.             }
  23.             if(!(game.equals("Hearthstone") || game.equals("Fornite") || game.equals("Overwatch"))){
  24.  
  25.                 others++;
  26.             }
  27.         }
  28.         double hearthstonePercent = hearthstone* 1.0/gamesSold * 100;
  29.         double fornitePercent = fornite* 1.0/gamesSold * 100;
  30.         double overwatchPercent = overwatch* 1.0/gamesSold * 100;
  31.         double othersPercent = others* 1.0/gamesSold * 100;
  32.  
  33.         System.out.printf("Hearthstone - %.2f%%%n",hearthstonePercent);
  34.         System.out.printf("Fornite - %.2f%%%n",fornitePercent);
  35.         System.out.printf("Overwatch - %.2f%%%n",overwatchPercent);
  36.         System.out.printf("Others - %.2f%%",othersPercent);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement