Daryan997

Programming - practice

Oct 11th, 2020
2,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. package javaapplication75;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class JavaApplication75 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.         System.out.println("Enter your array size:");
  10.         int size = input.nextInt();
  11.         int ar[] = new int[size];
  12.         int sum = 0;
  13.         for (int i = 0; i < ar.length; i++) {
  14.             System.out.println("Enter number for index " + i);
  15.             ar[i] = input.nextInt();
  16.             sum += ar[i];
  17.         }
  18.         System.out.println("Sum of the array: " + sum);
  19.     }
  20. }
Add Comment
Please, Sign In to add comment