deiom

Untitled

Jun 2nd, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Train {
  4.  
  5. //Train
  6. //You will be given a count of wagons in a train n. On the next n lines you will receive how many people are going to
  7. //get on that wagon. At the end print the whole train and after that the sum of the people in the train.
  8. //Examples
  9. //Input:
  10. //3
  11. //13
  12. //24
  13. //8
  14. //Output:
  15. // 13 24 8
  16. //45
  17. //Input:
  18. // 6
  19. //3
  20. //52
  21. //71
  22. //13
  23. //65
  24. //4
  25. //Output:
  26. //3 52 71 13 65 4
  27. //208
  28. //Input
  29. //1
  30. //100
  31. //Output
  32. //100
  33. //100
  34. public static void main(String[] args) {
  35. Scanner scanner = new Scanner(System.in);
  36.  
  37. int wagons= Integer.parseInt(scanner.nextLine());
  38. int [] train= new int[wagons];
  39.  
  40. for (int i=0; i<wagons;i++){
  41. int number = Integer.parseInt(scanner.nextLine());
  42. train[i]=number;
  43. }
  44. int count=0;
  45. for (int index=0;index<train.length;index++){
  46. int people = train[index];
  47.  
  48. count += people;
  49.  
  50. System.out.println(train+ " ");
  51. }
  52. System.out.print(count) ;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment