This Java program takes 10 integers as input from the user, stores them in an array a, and then calculates the sum of all the values in the array using a for-each loop.
Here is a breakdown of the code:
import java.util.Scanner; class Sum_Values_Array { public static void main(String[] args) { int [] a =new int[10]; int sum = 0; for(int i=0;i<10;i++) { Scanner input =new Scanner(System.in); System.out.printf("Element of a[%d] :",i); a[i]=input.nextInt(); } for (int i : a) sum += i; System.out.println("Sum Values of Array : " + sum); } }
Element of a[0] :1 Element of a[1] :2 Element of a[2] :3 Element of a[3] :4 Element of a[4] :5 Element of a[5] :6 Element of a[6] :7 Element of a[7] :8 Element of a[8] :9 Element of a[9] :10 Sum Values of Array : 55
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions