1. public static int add(int ... args){
int sum=0;
for(int arg:args){
sum+=arg;
}
return sum;
}
System.out.println(add(200,400,800));
结果:1400
2. public static int add(int x,int ... args){
int sum=0;
for(int arg:args){
sum+=arg;
}
return sum;
}
System.out.println(add(200,400,800));
结果:1200.
3. public static int add(int x,int y,int ... args){
int sum=0;
for(int arg:args){
sum+=arg;
}
return sum;
}
System.out.println(add(200,400,800));
结果:800.
我是真闹不懂了,怎么
add(int x,int ... args)就把200忽略了呢。求解
|