1 public class Text1{
 2     public static void main(String args[]){
 3         System.out.println("和等于:"+add(2,5));
 4         System.out.println("和等于:"+add(2,5,100,25,23));
 5         System.out.println("和等于:"+add());
 6         System.out.println("乘等于:"+cheng(2,4));
 7         System.out.println("乘等于:"+cheng(2,4,6));
 8         System.out.println("乘等于:"+cheng());
 9     }
10     public static int add(int ... arr){
11         int num=0;
12         assert arr.length==0;
13         for(int lemp:arr){
14             num+=lemp;
15         }
16         return num;
17     }
18     public static double cheng(double ... arr){
19         if(arr.length==0)
20         return 0.0;
21         double num=1;
22         for(double lemp:arr){
23             num*=lemp;
24         }
25         return num;
26     }
27 }

 

版权声明:本文为kaililikai原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/kaililikai/p/5890715.html