package Recursive;
import java.util.Arrays;
import java.util.Scanner;
public class Exercise18_13 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter 8 integers: ");
int[] list = new int[8];
for (int i = 0; i < list.length; i++)
list[i] = input.nextInt();
System.out.println("The max value in list " + Arrays.toString(list) + " is " + getMax(list));
}
/** 返回数组的最大数 */
public static int getMax(int[] list) {
return getMax(list, list.length-1, 0);
}
/** 返回数组的最大数辅助方法 */
private static int getMax(int[] list, int high, int max) {
return high == 0 ? list[high] : Math.max(list[high], getMax(list, high-1, max));
}
}