package test; import java.util.*; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.locks.Lock; import javax.print.attribute.IntegerSyntax; import org.omg.CosNaming.NamingContextExtPackage.AddressHelper; import privateclass.*; import java.io.*; public class Main { private static final String space_operator = " "; public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); /* * 可变参数1.5之后的新特性 */ int sum = add(1,2,3,4,5,78,5); System.out.println(sum); } //可变参数直接传送一个不知道有多少int的数组 //但是这个可变数组只能放到结尾 /* * 因为放在开头的时候后面的参数我们就无法传递 * */ private static int add(int... arr) { int sum = 0; for (int i = 0; i < arr.length; i ++) { sum += arr[i]; } return sum; } //我们放在前面的话就相当于把第一个数传递a /* * private static int add(int a,int... arr) { int sum = 0; for (int i = 0; i < arr.length; i ++) { sum += arr[i]; } return sum; } */ }