diff --git a/src/main/java/com/thealgorithms/maths/Average.java b/src/main/java/com/thealgorithms/maths/Average.java index 1c632cf0..6b9c2016 100644 --- a/src/main/java/com/thealgorithms/maths/Average.java +++ b/src/main/java/com/thealgorithms/maths/Average.java @@ -1,17 +1,23 @@ package com.thealgorithms.maths; /** - * Calculate average of a list of numbers + * A utility class for computing the average of numeric arrays. + * This class provides static methods to calculate the average of arrays + * of both {@code double} and {@code int} values. */ public final class Average { + + // Prevent instantiation of this utility class private Average() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated."); } /** - * Calculate average of a list of numbers + * Computes the average of a {@code double} array. * - * @param numbers array to store numbers - * @return mean of given numbers + * @param numbers an array of {@code double} values + * @return the average of the given numbers + * @throws IllegalArgumentException if the input array is {@code null} or empty */ public static double average(double[] numbers) { if (numbers == null || numbers.length == 0) { @@ -25,13 +31,13 @@ public final class Average { } /** - * find average value of an int array + * Computes the average of an {@code int} array. * - * @param numbers the array contains element and the sum does not excess long - * value limit - * @return average value + * @param numbers an array of {@code int} values + * @return the average of the given numbers + * @throws IllegalArgumentException if the input array is {@code null} or empty */ - public static int average(int[] numbers) { + public static double average(int[] numbers) { if (numbers == null || numbers.length == 0) { throw new IllegalArgumentException("Numbers array cannot be empty or null"); } @@ -39,6 +45,6 @@ public final class Average { for (int number : numbers) { sum += number; } - return (int) (sum / numbers.length); + return (double) (sum / numbers.length); } }