重载函数求最大值
//找出两个整型数,三个整型数或四个整型数中的最大值
public class Example{
static int max(int a,int b) {
if(a>b) {
return a;
}else
return b;
}
static int max(int a,int b,int c) {
int d=max(a,b);
int e=max(c,d);
return e;
}
static int max(int a,int b,int c,int d) {
int e=max(a,b,c);
int f=max(d,e);
return f;
}
public static void main(String[] args){
int a=15,b=-10,c=12,d=30;
int m;
m=max(a,b);
System.out.println("两个数中的最大值是:"+m);
m=max(a,b,c);
System.out.println("三个数中的最大值是:"+m);
m=max(a,b,c,d);
System.out.println("四个数中的最大值是:"+m);
}
}