Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Train {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int countWagons = Integer.parseInt(scanner.nextLine());
- int[] wagons = new int[countWagons];
- for (int wagon = 0; wagon < countWagons; wagon++) {
- int countPeople = Integer.parseInt(scanner.nextLine());
- wagons[wagon] = countPeople;
- }
- int sum = 0;
- for (int number : wagons) {
- System.out.print(number + " ");
- sum += number;
- }
- System.out.println();
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment