mystery7 methods

public static void constrain(int[] arr, int min, int max)
{
    constrain(arr, min, max, 0);
}

private static void constrain(int[] arr, int min, int max, int index)
{
    if(index >= arr.length)
        return;
    
    if(arr[index] < min)
        arr[index] = min;
    
    if(arr[index] > max)
        arr[index] = max;
    
    constrain(arr, min, max, index + 1);
}

The methods constrain each value in arr to be between min and max, inclusive.

This method should have a precondition that min <= max. It was intentionally omitted to avoid hinting at the solution.

mystery6 solution
mystery8 solution
Exercises
All solutions