可變引數例項

勤奋的小番茄發表於2024-08-17
 1 public class OverLoadExercise{
 2     public static void main(String[] args){
 3 
 4         Methods stu =  new Methods();
 5 
 6 
 7         System.out.println(stu.max(10,24));
 8 
 9 
10 
11     }
12 }
13 
14 
15 class Methods{
16 
17 
18 
19     public int max(int n1,int n2){
20         return n1 > n2 ? n1 : n2;
21     }
22     
23     public double max(double n1,double n2){
24         return n1 > n2 ? n1 : n2; 
25     }
26 
27     public double max(double n1,double n2,double n3){
28         double max1 =  n1 > n2 ? n1 : n2;
29         return max1 > n3 ? max1 : n3;
30     }
31 }

相關文章