Advertisement
mimisimi

Bus

Dec 16th, 2018
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package h_ExamPreparation.PreExam;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Problem05 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int pax  = Integer.parseInt(scanner.nextLine());
  9.         int busStops  = Integer.parseInt(scanner.nextLine());
  10.  
  11.         double oddPax = 0;
  12.         double evenPax = 0;
  13.         double totalPax = 0;
  14.  
  15.         for (int i = 1; i <= 2*busStops ; i++) {
  16.             int n  = Integer.parseInt(scanner.nextLine());
  17.             if (i % 2 == 0){
  18.                 evenPax += n;
  19.             }else {
  20.                 oddPax += n;
  21.             }
  22.             totalPax = pax + evenPax - oddPax;
  23.             if (busStops % 2 != 0){
  24.                 totalPax += 2;
  25.             }
  26.         }
  27.         System.out.printf("The final number of passengers is : %.0f",totalPax);
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement