package test;
public class myTest {
// 根据输入的参数动态生成数组
public static int max(int... param) {
int max = 0;
int length = param.length;
for (int i = 0; i < length; i++) {
if (max < param[i]) {
max = param[i];
}
}
return max;
}
public static void main(String[] args) {
int test1 = max(1, 2, 3, 5);
int test2 = max(0, 6, 3, 6, 9, 7);
System.out.println("test1=" + test1 + " test2=" + test2);
}
}
java不确定参数个数方法例子
最新推荐文章于 2024-08-17 02:08:56 发布