Advertisement
damesova

Bus - Java

Dec 16th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package TrialExam16Dec18;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Task_5 {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int startPeople = Integer.parseInt(scanner.nextLine());
  10. int nStations = Integer.parseInt(scanner.nextLine());
  11.  
  12. int sumIn = 0;
  13. int sumOut = 0;
  14.  
  15. for (int i = 1; i <= nStations; i++) {
  16. int nOut = Integer.parseInt(scanner.nextLine());
  17. int nIn = Integer.parseInt(scanner.nextLine());
  18.  
  19. if (i % 2 == 1) {
  20. nIn += 2;
  21. }
  22.  
  23. if (i % 2 == 0) {
  24. nOut += 2;
  25. }
  26.  
  27. sumIn += nIn;
  28. sumOut += nOut;
  29. }
  30.  
  31. int finalN = startPeople + sumIn - sumOut;
  32. System.out.printf("The final number of passengers is : %d", finalN);
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement