Q:

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

0

Java Program to sum the elements of an array by getting input from user using for loop

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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);
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now