方法的重载
方法名相同 参数列表不同(数据类型,数量,排列顺序) 返回值可以相同,可以不相同 返回值类型不同没用
package com. zzw. method;
public class Demo02 {
public static void main ( String[ ] args) {
int result01 = max ( 10 , 11 ) ;
double result02 = max ( 10.0 , 11.0 ) ;
int result03 = max ( 10 , 10 , 10 ) ;
System. out. println ( result01) ;
System. out. println ( result02) ;
System. out. println ( " ==============" ) ;
System. out. println ( result03) ;
}
public static int max ( int num1, int num2) {
int result = 0 ;
if ( num1 == num2) {
System. out. println ( num1 + "=" + num2) ;
return 0 ;
}
if ( num1 > num2) {
result = num1;
} else {
result = num2;
}
return result;
}
public static double max ( double num1, double num2) {
double result = 0.0 ;
if ( num1 == num2) {
System. out. println ( num1 + "=" + num2) ;
return 0 ;
}
if ( num1 > num2) {
result = num1;
} else {
result = num2;
}
return result;
}
public static int max ( int num1, int num2, int num3) {
int result = 0 ;
if ( num1 > num2) {
if ( num1 > num3) {
result = num1;
} else {
result = num3;
}
} else if ( num2 > num1) {
if ( num2 > num3) {
result = num2;
} else {
result = num3;
}
} else {
System. out. println ( num1 + "=" + num2 + "=" + num3) ;
return 0 ;
}
return result;
}
}
10 = 10 = 10
11
11.0
== == == == == == ==
0