MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / arithmetic

Method arithmetic

src/main/java/com/thealgorithms/maths/Means.java:49–54  ·  view source on GitHub ↗

Computes the arithmetic mean (average) of the given numbers. The arithmetic mean is calculated as: (x₁ + x₂ + ... + xₙ) / n Example: For numbers [2, 4, 6], the arithmetic mean is (2+4+6)/3 = 4.0 @param numbers the input numbers (must not be empty) @return the arithmetic mean of th

(final Iterable<Double> numbers)

Source from the content-addressed store, hash-verified

47 * Mean</a>
48 */
49 public static Double arithmetic(final Iterable<Double> numbers) {
50 checkIfNotEmpty(numbers);
51 double sum = StreamSupport.stream(numbers.spliterator(), false).reduce(0d, (x, y) -> x + y);
52 int size = IterableUtils.size(numbers);
53 return sum / size;
54 }
55
56 /**
57 * Computes the geometric mean of the given numbers.

Calls 3

checkIfNotEmptyMethod · 0.95
streamMethod · 0.80
sizeMethod · 0.65