Advertisement
veronikaaa86

Camp

Oct 25th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package Exam20November2016Morning;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Demo {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int quantityGroup = Integer.parseInt(scanner.nextLine());
  10.  
  11. double car = 0;
  12. double bus = 0;
  13. double miniBus = 0;
  14. double bigBus = 0;
  15. double train = 0;
  16. double allPeople = 0;
  17.  
  18. for (int i = 1; i <= quantityGroup; i++) {
  19. int quantityPeopleInGroup = Integer.parseInt(scanner.nextLine());
  20.  
  21. allPeople += quantityPeopleInGroup;
  22.  
  23. if (quantityPeopleInGroup <= 5) {
  24. car+=quantityPeopleInGroup; //Тук също ти го преправи, защото ти увеличаваше само с 1, а трябва да сумираш всички хора пътували с кола. И за другите проверки е същото.
  25. }else if (quantityPeopleInGroup <= 12) {
  26. bus+=quantityPeopleInGroup;
  27. }else if (quantityPeopleInGroup <= 25) {
  28. miniBus+=quantityPeopleInGroup;
  29. }else if (quantityPeopleInGroup <= 40) {
  30. bigBus+=quantityPeopleInGroup;
  31. }else {
  32. train+=quantityPeopleInGroup;
  33. }
  34. }
  35. //double allPeople = car + bus + miniBus + bigBus + train; Това го махнах и го сложих в цикъла, но малко променено
  36. System.out.printf("%.2f%%%n", car / allPeople * 100); // Процентите, които беше объркал :)
  37. System.out.printf("%.2f%%%n", bus / allPeople * 100);
  38. System.out.printf("%.2f%%%n", miniBus / allPeople * 100);
  39. System.out.printf("%.2f%%%n", bigBus / allPeople * 100);
  40. System.out.printf("%.2f%%", train / allPeople * 100);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement