Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*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.*/
- import java.util.Scanner;
- public class TestXXX {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int nWagons = scanner.nextInt();
- int[] train = new int[nWagons];
- int sum = 0;
- for (int i = 0; i < train.length ; i++) {
- train [i] = scanner.nextInt();
- sum += train[i];
- }
- for (int waggons : train) {
- System.out.printf("%d ",waggons);
- }
- System.out.println();
- System.out.println(sum);
- }
- }
Add Comment
Please, Sign In to add comment