Advertisement
GabrielHr00

TrekkingMania

Nov 20th, 2022
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. package S4_ForLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TrekkingMania {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. int groupsCount = Integer.parseInt(scanner.nextLine());
  9.  
  10. int sumAllPeople = 0;
  11. int sumPeopleForMusala = 0;
  12. int sumPeopleForMonblanc = 0;
  13. int sumPeopleForKilimandjaro = 0;
  14. int sumPeopleForK2 = 0;
  15. int sumPeopleForEverest = 0;
  16.  
  17.  
  18. for (int i = 1; i <= groupsCount; i++) {
  19. // read for each group - people in it
  20. int peopleInGroup = Integer.parseInt(scanner.nextLine());
  21.  
  22. // add people to all people variable
  23. // sumAllPeople = sumAllPeople + peopleInGroup
  24. sumAllPeople += peopleInGroup;
  25.  
  26. // check for number of people in group
  27. if(peopleInGroup <= 5) {
  28. sumPeopleForMusala = sumPeopleForMusala + peopleInGroup;
  29. } else if(peopleInGroup <= 12) {
  30. // sumPeopleForMonblanc = sumPeopleForMonblanc + peopleInGroup;
  31. sumPeopleForMonblanc += peopleInGroup;
  32. } else if(peopleInGroup <= 25) {
  33. sumPeopleForKilimandjaro += peopleInGroup;
  34. } else if(peopleInGroup <= 40) {
  35. sumPeopleForK2 += peopleInGroup;
  36. } else {
  37. sumPeopleForEverest += peopleInGroup;
  38. }
  39. }
  40.  
  41. // print percents for each group
  42. System.out.printf("%.2f%%%n", 1.0*sumPeopleForMusala / sumAllPeople * 100);
  43. System.out.printf("%.2f%%%n", 1.0*sumPeopleForMonblanc / sumAllPeople * 100);
  44. System.out.printf("%.2f%%%n", 1.0*sumPeopleForKilimandjaro / sumAllPeople * 100);
  45. System.out.printf("%.2f%%%n", 1.0*sumPeopleForK2 / sumAllPeople * 100);
  46. System.out.printf("%.2f%%%n", 1.0*sumPeopleForEverest / sumAllPeople * 100);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement