Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class TrainArray {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.         int sum = 0;
  10.  
  11.         int[] num = new int[n];
  12.  
  13.         for (int i = 0; i < num.length; i++) {
  14.             num[i] = Integer.parseInt(scanner.nextLine());
  15.         }
  16.  
  17.         for (int i = 0; i < num.length; i++) {
  18.  
  19.             System.out.print(num[i] + " ");
  20.  
  21.             sum += num[i];
  22.  
  23.         }
  24.         System.out.println(sum);
  25.  
  26.  
  27.  
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement