Java Program to Calculate Sum & Average of an Array

In this program, you'll learn to Calculate Sum & Average of an Array. This is done by using for loop.

First of all we have to define a class name "Average" that has int type array to contain some values .Now we take a double type data that calculates the average of array ( avg = sum / array.length). And finally it will display the result on the command prompt with message by using the System.out.println().

Calculate Sum & Average of an Array


When you run the program, the output will be:

Enter the length of the Array : 5
Array Element  0 : 25
Array Element  1 : 65
Array Element  2 : 30
Array Element  3 : 99
Array Element  4 : 48
Sum  = 267
Average = 53.4

أحدث أقدم