In the above Java program to calculate the average value of array elements, we will loop through each element using for loop and then adding and storing the value in sum variable and dividing it by the length of the array.
public class Array{
public static void main(String[] args) {
int[] numbers = new int[]{46, 35, 81, 0, 17, 82, 94};
//calculate sum of all array elements
int sum = 0;
for(int i=0; i < numbers.length ; i++)
sum = sum + numbers[i];
//calculate average value
double avg = sum / numbers.length;
System.out.println("Average value of the array elements is : " + avg);
}
}
Sample Output: Average value of the array elements is : 50.0