Advertisement
Guest User

Untitled

a guest
Jul 31st, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class pcGameShopJuly2019 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int gameNumber = Integer.parseInt(scanner.next());//брой продадени игри
  7.         int countHearthstone = 0;//брояч на различните видове игри
  8.         int countFornite = 0;
  9.         int countOverwatch = 0;
  10.         int countOthers = 0;
  11.         if (gameNumber > 0) {
  12.             for (int i = 1; i <= gameNumber; i++) {
  13.                 String gameName = scanner.next();
  14.                 switch (gameName) {
  15.                     case "Hearthstone":
  16.                         countHearthstone++;
  17.                         break;
  18.                     case "Fornite":
  19.                         countFornite++;
  20.                         break;
  21.                     case "Overwatch":
  22.                         countOverwatch++;
  23.                         break;
  24.                     default:
  25.                         countOthers++;
  26.                         break;
  27.                 }
  28.             }
  29.  
  30.             double hearthstonePercent = countHearthstone * 100.00 / gameNumber * 1.0;
  31.             double fornitePercent = countFornite * 100*1.0 / gameNumber * 1.0;
  32.             double overwatchPercent = countOverwatch *100*1.0/ gameNumber * 1.0;
  33.             double othersPercent = countOthers *100*1.0 / gameNumber * 1.0;
  34.  
  35.             System.out.printf("Hearthstone - %.2f%%\n", hearthstonePercent);
  36.             System.out.printf("Fornite - %.2f%%\n", fornitePercent);
  37.             System.out.printf("Overwatch - %.2f%%\n", overwatchPercent);
  38.             System.out.printf("Others - %.2f%%", othersPercent);
  39.         }
  40.     }
  41. }
  42.  
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement