public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(getMax(3,5,9,8,1));
}
public static int getMax(int a,int b) {
return a>b?a:b;
}
public static int getMax(int a,int b,int c) {
return getMax(getMax(a,b),c);
}
public static int getMax(int a,int b,int c,int d) {
return getMax(getMax(getMax(a,b),c),d);
}
/**
* 可变参数
*/
public static int getMax(int...a) {
System.out.println("可变参数举例......");
int max = a[0];
for (int i = 0; i < a.length; i++) {
if(max < a[i]) {
max = a[i];
}
}
return max;
}
}
写三个重载的方法,分别接收两个整数、三个整数、四个整数,返回其中的最大值
最新推荐文章于 2022-11-16 21:46:15 发布