public static void main(String[] args) {
System.out.println(add(1994,1992,1993,1994));
System.out.println(add(1995,1995,1997));
System.out.println(add(1994,1992,1993,1994,1995,1995,1997));
}
// 调用可变参数方法求数组的和
public static int add(int... args) { //注意变量类型要符合转换要求!
int sum = 0;
for (int i : args) {
sum += i;
}
return sum;
}