Advertisement
skipter

SoftUni Camp - Java Basics - Exam 20 Nov

Apr 29th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FOX {
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.  
  7.         int howManyGroupsAre = Integer.parseInt(input.nextLine());
  8.  
  9.         int car = 0;
  10.         int microbus = 0;
  11.         int smallBus = 0;
  12.         int bigBus = 0;
  13.         int train = 0;
  14.  
  15.         for (int i = 0; i < howManyGroupsAre; i++) {
  16.  
  17.             int currentNumber = Integer.parseInt(input.nextLine());
  18.  
  19.             if (currentNumber >= 1 & currentNumber <= 5) {
  20.                 car += currentNumber;
  21.             } else if (currentNumber >= 6 & currentNumber <= 12) {
  22.                 microbus += currentNumber;
  23.             } else if (currentNumber >= 13 & currentNumber <= 25) {
  24.                 smallBus += currentNumber;
  25.             } else if (currentNumber >= 26 & currentNumber <= 40) {
  26.                 bigBus += currentNumber;
  27.             } else if (currentNumber >= 41) {
  28.                 train += currentNumber;
  29.             }
  30.         }
  31.  
  32.         int allStudents = car + microbus + smallBus + bigBus + train;
  33.  
  34.         System.out.printf("%.2f%%%n",(double) car/allStudents*100);
  35.         System.out.printf("%.2f%%%n",(double) microbus/allStudents*100);
  36.         System.out.printf("%.2f%%%n",(double) smallBus/allStudents*100);
  37.         System.out.printf("%.2f%%%n",(double) bigBus/allStudents*100);
  38.         System.out.printf("%.2f%%%n",(double) train/allStudents*100);
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement