In this program, you will learn to find the sum of all elements of an array in Java. This program calculating the addition of all the numbers which are initialized.
1 2 3 4 5 6 7 8 9 10 11 12 |
public class SumofArray { public static void main(String[] args) { int sum=0; int a[] = {1,2,3,4,5,6,7,8,9,10}; for(int i=0;i<=a.length;i++) { sum = sum + i; } System.out.println("Sum of Array Elements: "+sum); } } |
1 |
Sum of Array Elements: 55 |