galinyotsev123

ProgBasicsExam1and2December2018-E05trekkingMania

Dec 29th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E05trekkingMania {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double peopleInGroup1 = 0;
  8. double peopleInGroup2 = 0;
  9. double peopleInGroup3 = 0;
  10. double peopleInGroup4 = 0;
  11. double peopleInGroup5 = 0;
  12.  
  13. int n = Integer.parseInt(scanner.nextLine());
  14. for (int i = 0; i < n; i++) {
  15. int quantityPeopleInGroup = Integer.parseInt(scanner.nextLine());
  16.  
  17. if(quantityPeopleInGroup <= 5){
  18. peopleInGroup1+=quantityPeopleInGroup;
  19. }
  20.  
  21. else if(quantityPeopleInGroup >= 6 && quantityPeopleInGroup <= 12){
  22. peopleInGroup2+=quantityPeopleInGroup;
  23. }
  24.  
  25. else if(quantityPeopleInGroup >= 13 && quantityPeopleInGroup <=25){
  26. peopleInGroup3+=quantityPeopleInGroup;
  27. }
  28.  
  29. else if(quantityPeopleInGroup >= 26 && quantityPeopleInGroup <=40){
  30. peopleInGroup4+=quantityPeopleInGroup;
  31. }
  32.  
  33. else if(quantityPeopleInGroup >= 40){
  34. peopleInGroup5+=quantityPeopleInGroup;
  35. }
  36.  
  37. }
  38.  
  39. double sum = peopleInGroup1 + peopleInGroup2 + peopleInGroup3 + peopleInGroup4 + peopleInGroup5;
  40.  
  41. System.out.printf("%.2f%%%n", ( peopleInGroup1/ sum ) * 100);
  42. System.out.printf("%.2f%%%n", (peopleInGroup2 / sum) * 100);
  43. System.out.printf("%.2f%%%n", (peopleInGroup3 / sum) * 100);
  44. System.out.printf("%.2f%%%n", (peopleInGroup4 / sum) * 100);
  45. System.out.printf("%.2f%%%n", (peopleInGroup5 / sum) * 100);
  46.  
  47. }
  48. }
Add Comment
Please, Sign In to add comment