Blog

Articles to grow your career

Article

Arithmetic mean (average) in Java – Algorithms for interview

Consider the implementation of the algorithm for finding the arithmetic mean of the array elements.

First, in a loop, we will iterate over all the elements of the array and calculate their sum. Then we divide the sum by the length of the array:

public class ArithmeticAverage {
public static void main(String[] args) {
double[] nums = {10.

Do you want to join us?

Leave an application and get a free consultation from our manager.

  • Help in choosing a direction
  • Course consultation
  • Additional materials for the start

1, 11.2, 12.3, 13.4, 14.5};
double result = 0;

for (double d : nums) {
result += d;
}
System.out.println(“Arithmetic Average ” + result / nums.length);
}
}

Alex Kara
By Alex Kara on Apr 01, 2022
Coding tasks for interviews