- import java.util.Scanner;
-
- class ArraySum
- {
- public static void main(String args[])
- {
- Scanner in = new Scanner(System. in );
- System.out.println("Enter the number of elements in array:");
- int elements = ( in .nextInt());
- int[] array = new int[10];
- int sum = 0;
- System.out.println("Enter the elements:");
- for (int i = 0; i < elements; i++)
- {
- array[i] = in .nextInt();
- }
- for (int num: array)
- {
- sum = sum + num;
- }
- System.out.println("Sum of array elements is: " + sum);
- }
- }
Thank you, keep learning and sharing