package hiwari;
/*
* 定义一个Max类,其中包括两个重载方法gemax,
* 分别可返回2个整数中的最大值和三个整数中的最大值,
* 并在主函数中创建max类对象,分别求(2,3)的最大值和(2,8,100)中的最大值
* */
public class Max {
int getmax(int a,int b)
{
if (a>b) return a;
else return b;
}
int getmax(int a,int b,int c)
{
if(a>b)
if(a>c) return a;
else return c;
else if(b>c) return b;
else return c;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Max bb=new Max();
System.out.print(bb.getmax(9, 5, 12));
System.out.print(bb.getmax(2,4));
}
}
【水汐のjava】定义一个Max类,其中包括两个重载方法gemax,分别可返回2个整数中的最大值和三个整数中的最大值,并在主函数中创建max类对象,分别求(2,3)的最大值和(2,8,100)中的最大
最新推荐文章于 2023-06-19 11:21:47 发布