Didart

Train

Oct 3rd, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Train {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int countWagons = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int[] wagons = new int[countWagons];
  10.  
  11.         for (int wagon = 0; wagon < countWagons; wagon++) {
  12.             int countPeople = Integer.parseInt(scanner.nextLine());
  13.             wagons[wagon] = countPeople;
  14.         }
  15.         int sum = 0;
  16.         for (int number : wagons) {
  17.             System.out.print(number + " ");
  18.             sum += number;
  19.         }
  20.         System.out.println();
  21.         System.out.println(sum);
  22.     }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment