源码
package sto.pdd.util;
public class VariableParameter {
/* 求若干个整型数中的最大值
* 可变参数items
*/
public static int getMax(int... items){
int max = Integer.MIN_VALUE;
for(int item : items){
max = item > max? item : max;
}
return max;
}
public static void main(String[] args) {
// items是一个整型数组
int[] items = { 2, 5, 20, 6, 9 };
System.out.println("最大值:" + getMax(2, 1, 4, 7, 2, -1, 3, 3));
System.out.println("最大值:" + getMax(items));
}
}