Advertisement
Spocoman

Bus

Sep 2nd, 2024
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int passengers = Integer.parseInt(scanner.nextLine()),
  7.                 stations = Integer.parseInt(scanner.nextLine()),
  8.                 outputPassengers, inputPassengers;
  9.  
  10.         for (int i = 1; i <= stations; i++) {
  11.             outputPassengers = Integer.parseInt(scanner.nextLine());
  12.             inputPassengers = Integer.parseInt(scanner.nextLine());
  13.             passengers += inputPassengers - outputPassengers;
  14.  
  15.             if (i % 2 == 1) {
  16.                 passengers += 2;
  17.             } else {
  18.                 passengers -= 2;
  19.             }
  20.         }
  21.  
  22.         System.out.println("The final number of passengers is : " + passengers);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement