Java Programming

Array Sum

Java example for calculating sum of array elements

9/6/2021
0 views
array-elements-sum.javaJava
import java.io.*;

class arraysum {
	public static void main(String args[ ]) {

		/* Declaration of integer type array and initialize with 10 values */
		int array[ ] = {1,2,3,4,5,6,7,8,9,10};
		int ans = 0;
		for(int i = 0; i < 10; i++)
			ans += array[i];
		System.out.println("Sum of Array: "+ans);
	}
}


/* Output */
Sum of Array: 55
Sum of array elementsArray SumJava tutorial

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com