- public class AddTest{
- public static void main(String[] args) {
-
- System.out.println("sum=="+add(2,3,5));//2传给了x; 3,5传给了args.
- }
- public static int add(int x,int...args){
- int sum = 0;//这里改成int sun=x;就行了
- for(int i=0;i<args.length;i++){
- sum=sum+args[i];
- }
- return sum;
- }
- }
复制代码 |