Core Java
Java Program to Calculate Average Using Arrays
A quick and practical guide to find and to calculate the average of numbers in array using java language.
1. Overview
In this article, you’ll learn how to calculate the average of numbers using arrays.
You should know the basic concepts of a java programming language such as Sign up


There is a mistake in both programs. If You divide in Java two integers, You will get an integer result. To correct it cast at least one of the operands to double, like this:double average = (double)sum/length;
Better method:
double average = arrray.stream()
.mapToDouble(Integer::doubleValue)
.average()
.orElse(0.0);