//可变参数
public class Demo4 {
//计算任意数量的整数的和
public int sum(int ...args){//可变参数就当做数组来用
int sum = 0;
for(int i:args){
sum+=i;
}
return sum;
}
@Test//如何使用带有可变参数的方法
public void test1(){
int result = sum(1,2,3,4);
System.out.println(result);
}
@Test
public void test2(){
int values[] = {1,2,3,4,5};
int result = sum(values);
System.out.println(result);
}
public String aa(String s2,String...s1){
return null;
}
}