veronikaaa86

07. Trekking Mania

Jan 30th, 2022
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. package forLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07TrekkingMania {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int groups = Integer.parseInt(scanner.nextLine());//4
  10.  
  11. int allPeople = 0;
  12. int musalaPeople = 0;
  13. int montblanPeople = 0;
  14. int kilimandzharoPeople = 0;
  15. int k2People = 0;
  16. int everestPeople = 0;
  17. for (int i = 1; i <= groups; i++) {
  18. int peopleInGroup = Integer.parseInt(scanner.nextLine());
  19.  
  20. allPeople = allPeople + peopleInGroup;
  21.  
  22. if (peopleInGroup <= 5) {
  23. musalaPeople = musalaPeople + peopleInGroup;
  24. } else if (peopleInGroup <= 12) {
  25. montblanPeople = montblanPeople + peopleInGroup;
  26. } else if (peopleInGroup <= 25) {
  27. kilimandzharoPeople = kilimandzharoPeople + peopleInGroup;
  28. } else if (peopleInGroup <= 40) {
  29. k2People = k2People + peopleInGroup;
  30. } else {
  31. everestPeople = everestPeople + peopleInGroup;
  32. }
  33. }
  34.  
  35. System.out.printf("%.2f%%", musalaPeople * 1.0 / allPeople * 100);
  36. System.out.println();
  37. System.out.printf("%.2f%%", montblanPeople * 1.0 / allPeople * 100);
  38. System.out.println();
  39. System.out.printf("%.2f%%", kilimandzharoPeople * 1.0 / allPeople * 100);
  40. System.out.println();
  41. System.out.printf("%.2f%%", k2People * 1.0 / allPeople * 100);
  42. System.out.println();
  43. System.out.printf("%.2f%%", everestPeople * 1.0 / allPeople * 100);
  44. System.out.println();
  45. }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment