Advertisement
veronikaaa86

04. Trekking Mania

Apr 22nd, 2023
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04TrekkingMania {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int sumMusala = 0;
  10.         int sumMontblanc = 0;
  11.         int sumKilimanjaro = 0;
  12.         int sumK2 = 0;
  13.         int sumEverest = 0;
  14.  
  15.         int totalSum = 0;
  16.  
  17.         int countGroups = Integer.parseInt(scanner.nextLine());
  18.         for (int i = 1; i <= countGroups; i++) {
  19.             int people = Integer.parseInt(scanner.nextLine());
  20.  
  21.             totalSum += people;
  22.  
  23.             if (people <= 5) {
  24.                 sumMusala += people;
  25.             } else if (people <= 12) {
  26.                 sumMontblanc += people;
  27.             } else if (people <= 25) {
  28.                 sumKilimanjaro += people;
  29.             } else if (people <= 40) {
  30.                 sumK2 += people;
  31.             } else {
  32.                 sumEverest += people;
  33.             }
  34.         }
  35.  
  36.         double percentMusala = sumMusala * 1.0 / totalSum * 100;
  37.         System.out.printf("%.2f%%%n", percentMusala);
  38.         double percentMontblanc = sumMontblanc * 1.0 / totalSum * 100;
  39.         System.out.printf("%.2f%%%n", percentMontblanc);
  40.         double percentKilimanjaro = sumKilimanjaro * 1.0 / totalSum * 100;
  41.         System.out.printf("%.2f%%%n", percentKilimanjaro);
  42.         double percentK2 = sumK2 * 1.0 / totalSum * 100;
  43.         System.out.printf("%.2f%%%n", percentK2);
  44.         double percentEverest = sumEverest * 1.0 / totalSum * 100;
  45.         System.out.printf("%.2f%%%n", percentEverest);
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement