Below is a program that calculates the average value of an array using Java.

public static void main(String[] args) 
                int[] arr= new int[]{1,2,3,4,5};
                int sum = 0;
                for(int count=0; count < arr.length ; count++)
                        sum = sum + arr[count];
                double average = sum / arr.length;
                System.out.println("The average value of the array elements is : " + average);

Happy Coding!

More Java Snippets


Last modified: May 20, 2019


Write a Reply or Comment

Your email address will not be published.