public class Demo01 {
public static void main(String[] args) {
int max = max(50,30);//调用int类型方法
double Max = max(50,30);//调用double类型方法
System.out.println(max);//输出int类型
System.out.println(Max);//输出double类型
}
//比大小方法
public static int max(int a, int b){
int result = 0;
if(a == b){
return 0;
}
else {
return (a>b?a:b);
}
}
//重载方法,方法重名时,编译器根据形参不同选择对应方法
public static double max(double a, double b){
int result = 0;
if(a == b){
return 0;
}
else {
return (a>b?a:b);
}
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交