# 如何找到一組變量的最大值

// Ask for quarter values.
System.out.println("What is the value of the first quarter?");
firstQuarter = input.nextDouble();

System.out.println("What is the value of the second quarter?");
secondQuarter = input.nextDouble();

System.out.println("What is the value of the third quarter?");
thirdQuarter = input.nextDouble();

System.out.println("What is the value of the fourth quarter?");
fourthQuarter = input.nextDouble();

//Tell client the maximum value/price of the stock during the year.
//maxStock = This is where I need help
System.out.println("The maximum price of a stock share in the year is: \$" + maxStock + ".");


## 最佳答案

public static > T max(T...values) {
if (values.length <= 0)
throw new IllegalArgumentException();

T m = values[0];
for (int i = 1; i < values.length; ++i) {
if (values[i].compareTo(m) > 0)
m = values[i];
}

return m;
}