Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exam20November2016Morning;
- import java.util.Scanner;
- public class Demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int quantityGroup = Integer.parseInt(scanner.nextLine());
- double car = 0;
- double bus = 0;
- double miniBus = 0;
- double bigBus = 0;
- double train = 0;
- double allPeople = 0;
- for (int i = 1; i <= quantityGroup; i++) {
- int quantityPeopleInGroup = Integer.parseInt(scanner.nextLine());
- allPeople += quantityPeopleInGroup;
- if (quantityPeopleInGroup <= 5) {
- car+=quantityPeopleInGroup; //Тук също ти го преправи, защото ти увеличаваше само с 1, а трябва да сумираш всички хора пътували с кола. И за другите проверки е същото.
- }else if (quantityPeopleInGroup <= 12) {
- bus+=quantityPeopleInGroup;
- }else if (quantityPeopleInGroup <= 25) {
- miniBus+=quantityPeopleInGroup;
- }else if (quantityPeopleInGroup <= 40) {
- bigBus+=quantityPeopleInGroup;
- }else {
- train+=quantityPeopleInGroup;
- }
- }
- //double allPeople = car + bus + miniBus + bigBus + train; Това го махнах и го сложих в цикъла, но малко променено
- System.out.printf("%.2f%%%n", car / allPeople * 100); // Процентите, които беше объркал :)
- System.out.printf("%.2f%%%n", bus / allPeople * 100);
- System.out.printf("%.2f%%%n", miniBus / allPeople * 100);
- System.out.printf("%.2f%%%n", bigBus / allPeople * 100);
- System.out.printf("%.2f%%", train / allPeople * 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement