Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/sorts/RadixSort.java (Java)

Code before:
package com.thealgorithms.sorts;

import java.util.Arrays;

/**
 * This class provides an implementation of the radix sort algorithm.
 * It sorts an array of integers in increasing order.
 */
public final class RadixSort {
    private RadixSort() {
    }

    /**
     * Sorts an array of integers using the radix sort algorithm.
     *
     * @param array the array to be sorted
     * @return the sorted array
     */
    public static int[] sort(int[] array) {
        if (array.length == 0) {
            return array;
        }

        final int max = Arrays.stream(array).max().getAsInt();
        for (int exp = 1; max / exp > 0; exp *= 10) {
            countingSortByDigit(array, exp);
        }

        return array;
    }

    /**
     * A utility method to perform counting sort of array[] according to the digit represented by exp.
     *
     * @param array the array to be sorted
     * @param exp   the exponent representing the current digit position
     */
    private static void countingSortByDigit(int[] array, int exp) {
        int[] output = new int[array.length];
        int[] count = new int[10];

        for (int i = 0; i < array.length; i++) {
            count[(array[i] / exp) % 10]++;
        }

        for (int i = 1; i < 10; i++) {
            count[i] += count[i - 1];
        }

        for (int i = array.length - 1; i >= 0; i--) {

Review comment (suggestion):
Please consider using [`NumberOfDigits`](https://github.com/TheAlgorithms/Java/blob/57878cac555eebf33a86b3d808e7b91f26174458/src/main/java/com/thealgorithms/maths/NumberOfDigits.java) to determine the number of iterations in the loop.

Code after:
package com.thealgorithms.sorts;

import com.thealgorithms.maths.NumberOfDigits;
import java.util.Arrays;

/**
 * This class provides an implementation of the radix sort algorithm.
 * It sorts an array of nonnegative integers in increasing order.
 */
public final class RadixSort {
    private static final int BASE = 10;

    private RadixSort() {
    }

    /**
     * Sorts an array of nonnegative integers using the radix sort algorithm.
     *
     * @param array the array to be sorted
     * @return the sorted array
     * @throws IllegalArgumentException if any negative integers are found
     */
    public static int[] sort(int[] array) {
        if (array.length == 0) {
            return array;
        }

        checkForNegativeInput(array);
        radixSort(array);
        return array;
    }

    /**
     * Checks if the array contains any negative integers.
     *
     * @param array the array to be checked
     * @throws IllegalArgumentException if any negative integers are found
     */
    private static void checkForNegativeInput(int[] array) {
        for (int number : array) {
            if (number < 0) {
                throw new IllegalArgumentException("Array contains non-positive integers.");
            }
        }
    }

    private static void radixSort(int[] array) {
        final int max = Arrays.stream(array).max().getAsInt();
        for (int i = 0, exp = 1; i < NumberOfDigits.numberOfDigits(max); i++, exp *= BASE) {
            countingSortByDigit(array, exp);