Advertisement
finderabc

BUS ( Exam - 16 December 2018 )

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