Java

Program to find the average of numbers using array.

Program to find the average of numbers using array.
public class demo1 {

    public static void main(String[] args) {
        double[] arr = {10.5, 10, 10.5, 10, 10.5};
        double total = 0;

        for(int i=0; i<arr.length; i++){
        	total = total + arr[i];
        }
        double average = total / arr.length; 
        System.out.format("The average is: %.3f", average);
    }
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.