方法的重载
1 package method; 2 3 public class Demo02 { 4 public static void main(String[] args) { 5 double max = max(20, 10); 6 System.out.println(max); 7 } 8 //比大小方法(int2) 9 public static int max(int num1,int num2){ 10 int result = 0 ; 11 if (num1 == num2){ 12 System.out.println("num1==num2"); 13 return 0;//终止方法 14 } 15 16 if (num1 > num2) result = num1; 17 else { 18 result = num2; 19 } 20 return result; 21 } 22 //比大小方法(double) 23 public static double max(double num1,double num2){ 24 double result = 0 ; 25 if (num1 == num2){ 26 System.out.println("num1==num2"); 27 return 0;//终止方法 28 } 29 30 if (num1 > num2) result = num1; 31 else { 32 result = num2; 33 } 34 return result; 35 } 36 //比大小方法(int3) 37 public static int max(int num1,int num2,int num3){ 38 int result = 0 ; 39 if (num1 == num2){ 40 System.out.println("num1==num2"); 41 return 0;//终止方法 42 } 43 44 if (num1 > num2) result = num1; 45 else { 46 result = num2; 47 } 48 return result; 49 } 50 }