Advertisement
veronikaaa86

05. PC Game Shop

Apr 9th, 2022
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. package examPreparation;
  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 nameGame = scanner.nextLine();
  17.  
  18. switch (nameGame) {
  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. break;
  31. }
  32. }
  33.  
  34. System.out.printf("Hearthstone - %.2f%%%n", hearthstoneCount * 1.0 / n * 100);
  35. System.out.printf("Fornite - %.2f%%%n", forniteCount * 1.0 / n * 100);
  36. System.out.printf("Overwatch - %.2f%%%n", overWatchCount * 1.0 / n * 100);
  37. System.out.printf("Others - %.2f%%%n", otherCount * 1.0 / n * 100);
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement