galinyotsev123

ProgBasicsExam3and4November2018-E05weddingPresents

Jan 4th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E05weddingPresents {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int counterA = 0;
  8. int counterB = 0;
  9. int counterV = 0;
  10. int counterG = 0;
  11.  
  12. double percentageA = 0;
  13. double percentageB = 0;
  14. double percentageV = 0;
  15. double percentageG = 0;
  16. double percentageAllGifts = 0;
  17.  
  18. double guests = Double.parseDouble(scanner.nextLine());
  19. double gifts = Double.parseDouble(scanner.nextLine());
  20.  
  21.  
  22. for (int i = 0; i < gifts; i++) {
  23. String category = scanner.nextLine();
  24.  
  25. if (category.equals("A")){
  26. counterA++;
  27. }
  28. else if (category.equals("B")){
  29. counterB++;
  30. }
  31. else if (category.equals("V")){
  32. counterV++;
  33. }
  34. else if (category.equals("G")){
  35. counterG++;
  36. }
  37. percentageAllGifts = gifts / guests * 100;
  38.  
  39. }
  40.  
  41. System.out.printf("%.2f%%%n", counterA / gifts * 100);
  42. System.out.printf("%.2f%%%n", counterB / gifts * 100);
  43. System.out.printf("%.2f%%%n", counterV / gifts * 100);
  44. System.out.printf("%.2f%%%n", counterG / gifts * 100);
  45. System.out.printf("%.2f%%%n", gifts / guests * 100);
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment