Advertisement
Guest User

WeddingPresents

a guest
Dec 14th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class WeddingPresents {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. int guests = Integer.parseInt(sc.nextLine());
  8. int gifts = Integer.parseInt(sc.nextLine());
  9.  
  10. int moneyGifts = 0; // A
  11. int urediGifts = 0; // B
  12. int vaucheriGifts = 0; // V
  13. int otherGifts = 0; // G
  14.  
  15. for (int i = 1; i <= gifts; i++) {
  16. String input = sc.nextLine();
  17. if (input.equals("A")) {
  18. moneyGifts++;
  19. } else if (input.equals("B")) {
  20. urediGifts++;
  21. } else if (input.equals("V")) {
  22. vaucheriGifts ++;
  23. } else if (input.equals("G")) {
  24. otherGifts++;
  25. }
  26. }
  27. double percentMoney = moneyGifts * 1.0 / gifts * 100;
  28. double percentUredi = urediGifts * 1.0 / gifts * 100;
  29. double percentVaucheri = vaucheriGifts * 1.0 / gifts * 100;
  30. double percentOthers = otherGifts * 1.0 / gifts * 100;
  31. double percentGuests = gifts * 1.0 / guests * 100;
  32.  
  33. System.out.printf("%.2f%%\n%.2f%%\n%.2f%%\n%.2f%%\n%.2f%%", percentMoney, percentUredi, percentVaucheri, percentOthers, percentGuests);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement