It's like a nightmare that doesn't go away when you wake up. Many of the patterns we have seen for traversing arrays can also be written recursively. It is not common to do so, but it is a useful exercise.
This method should be recursive. If the length of the range is 1, that is, if low == high, we know immediately that the sole element in the range must be the maximum. So that's the base case. If the array is bigger than 1, we can break the array into two pieces, find the maximum in each of the pieces, and then find the maximum of each of the piece-maxima.
public static int max (int[] a) {
return maxInRange (a, 0, a.length-1);
}
The wrapper method uses the worker method to do the real
work. The role of the wrapper is to provide an interface to
the outside world that is easier to use.