Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Train {
- //Train
- //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
- //get on that wagon. At the end print the whole train and after that the sum of the people in the train.
- //Examples
- //Input:
- //3
- //13
- //24
- //8
- //Output:
- // 13 24 8
- //45
- //Input:
- // 6
- //3
- //52
- //71
- //13
- //65
- //4
- //Output:
- //3 52 71 13 65 4
- //208
- //Input
- //1
- //100
- //Output
- //100
- //100
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int wagons= Integer.parseInt(scanner.nextLine());
- int [] train= new int[wagons];
- for (int i=0; i<wagons;i++){
- int number = Integer.parseInt(scanner.nextLine());
- train[i]=number;
- }
- int count=0;
- for (int index=0;index<train.length;index++){
- int people = train[index];
- count += people;
- System.out.println(train+ " ");
- }
- System.out.print(count) ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment