Advertisement
Guest User

Bus

a guest
Dec 18th, 2018
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. package examPB_16Dec2018;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Task5_Bus {
  6. public static void main(String[] args) {
  7. @SuppressWarnings("resource")
  8.  
  9. Scanner sc = new Scanner(System.in);
  10. int peopleStart = Integer.parseInt(sc.nextLine());
  11. int stops = Integer.parseInt(sc.nextLine());
  12.  
  13. for (int i = 1; i <= stops; i++) {
  14. int peopleOut = Integer.parseInt(sc.nextLine());
  15. int peopleIn = Integer.parseInt(sc.nextLine());
  16. peopleStart -= peopleOut;
  17. peopleStart += peopleIn;
  18. if (i % 2 == 1) {
  19. peopleStart += 2;
  20. } else {
  21. peopleStart -= 2;
  22. }
  23. }
  24.  
  25. System.out.printf("The final number of passengers is : %d", peopleStart);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement