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

Venkatesh Nukala

Venkatesh Nukala is a Software Engineer working for Online Payments Industry Leading company. In my free time, I would love to spend time with family and write articles on technical blogs. More on JavaProgramTo.com
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Aaaa
Aaaa
2 years ago

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;

Bill Fly
Bill Fly
1 year ago

Better method:

double average = arrray.stream()
.mapToDouble(Integer::doubleValue)
.average()
.orElse(0.0);

Back to top button