Java

Program to sum the elements of an array by getting input from user.

Program to sum the elements of an array by getting input from user.
import java.util.Scanner;
class demo1{
   public static void main(String args[]){
      Scanner n = new Scanner(System.in);
      int[] array = new int[10];
      int sum = 0;
      System.out.println("Enter the elements:");
      for (int i=0; i<10; i++)
      {
    	  array[i] = n.nextInt();
      }
      for( int num : array) {
          sum = sum+num;
      }
      System.out.println("Sum of array elements is:"+sum);
   }
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.