Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package examPB_16Dec2018;
- import java.util.Scanner;
- public class Task5_Bus {
- public static void main(String[] args) {
- @SuppressWarnings("resource")
- Scanner sc = new Scanner(System.in);
- int peopleStart = Integer.parseInt(sc.nextLine());
- int stops = Integer.parseInt(sc.nextLine());
- for (int i = 1; i <= stops; i++) {
- int peopleOut = Integer.parseInt(sc.nextLine());
- int peopleIn = Integer.parseInt(sc.nextLine());
- peopleStart -= peopleOut;
- peopleStart += peopleIn;
- if (i % 2 == 1) {
- peopleStart += 2;
- } else {
- peopleStart -= 2;
- }
- }
- System.out.printf("The final number of passengers is : %d", peopleStart);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement