import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while(sc.hasNext()){System.out.println("请输入需要累加的个数");int n = sc.nextInt();sc.nextLine(); // 清除输入缓冲区中的剩余内容int[] vars = new int[n];for(int i=0; i<n; i++){vars[i] = sc.nextInt();}int res = sum(vars);System.out.println("累加结果:"+res);}}public static int sum(int... a){int res=0;if(a==null)return 0;else{for (int i : a) {res+=i;}return res;}}
}
最终还是没解决!#_#