Advertisement
veronikaaa86

04. PC Game Shop

Jun 19th, 2021
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 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());//4
  10.  
  11. int hearthstoneCount = 0;
  12. int forniteCount = 0;
  13. int overwatchCount = 0;
  14. int otherCount = 0;
  15.  
  16. for (int i = 1; i <= n; i++) {
  17. String gameName = scanner.nextLine();
  18.  
  19. switch (gameName) {
  20. case "Hearthstone":
  21. hearthstoneCount++;
  22. break;
  23. case "Fornite":
  24. forniteCount++;
  25. break;
  26. case "Overwatch":
  27. overwatchCount++;
  28. break;
  29. default:
  30. otherCount++;
  31. break;
  32. }
  33. }
  34.  
  35. System.out.printf("Hearthstone - %.2f%%%n", hearthstoneCount * 1.0 / n * 100);
  36. System.out.printf("Fornite - %.2f%%%n", forniteCount * 1.0 / n * 100);
  37. System.out.printf("Overwatch - %.2f%%%n", overwatchCount * 1.0 / n * 100);
  38. System.out.printf("Others - %.2f%%%n", otherCount * 1.0 / n * 100);
  39. }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement