Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S4_ForLoops;
- import java.util.Scanner;
- public class TrekkingMania {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int groupsCount = Integer.parseInt(scanner.nextLine());
- int sumAllPeople = 0;
- int sumPeopleForMusala = 0;
- int sumPeopleForMonblanc = 0;
- int sumPeopleForKilimandjaro = 0;
- int sumPeopleForK2 = 0;
- int sumPeopleForEverest = 0;
- for (int i = 1; i <= groupsCount; i++) {
- // read for each group - people in it
- int peopleInGroup = Integer.parseInt(scanner.nextLine());
- // add people to all people variable
- // sumAllPeople = sumAllPeople + peopleInGroup
- sumAllPeople += peopleInGroup;
- // check for number of people in group
- if(peopleInGroup <= 5) {
- sumPeopleForMusala = sumPeopleForMusala + peopleInGroup;
- } else if(peopleInGroup <= 12) {
- // sumPeopleForMonblanc = sumPeopleForMonblanc + peopleInGroup;
- sumPeopleForMonblanc += peopleInGroup;
- } else if(peopleInGroup <= 25) {
- sumPeopleForKilimandjaro += peopleInGroup;
- } else if(peopleInGroup <= 40) {
- sumPeopleForK2 += peopleInGroup;
- } else {
- sumPeopleForEverest += peopleInGroup;
- }
- }
- // print percents for each group
- System.out.printf("%.2f%%%n", 1.0*sumPeopleForMusala / sumAllPeople * 100);
- System.out.printf("%.2f%%%n", 1.0*sumPeopleForMonblanc / sumAllPeople * 100);
- System.out.printf("%.2f%%%n", 1.0*sumPeopleForKilimandjaro / sumAllPeople * 100);
- System.out.printf("%.2f%%%n", 1.0*sumPeopleForK2 / sumAllPeople * 100);
- System.out.printf("%.2f%%%n", 1.0*sumPeopleForEverest / sumAllPeople * 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement