java.控制次数,每一组数都要计算。所以有个嵌套

总结:数组内的数据要循环,外面的次数也要循环

package com.aini;

import java.util.Scanner;

//要求可以控制输入的次数,比如4次。则输入5个数,5组输出结果
public class DFSDFG {

	public static void main(String[] args) {
		Scanner c = new Scanner(System.in);
		int x = c.nextInt();
		int a[] = new int[x];
		int s = 0;
		for (int i = 0; i < x; i++) {
			for (int i1 = 0; i1 < x; i1++) {
				System.out.println("输入" + "第" + (i1 + 1) + "个数");
				a[i1] = c.nextInt();
				s += a[i1];

			}
			System.out.println("和是:" + s);
		}
	}
}
//
3
输入第1个数
423
输入第2个数
2
输入第3个数
1
1和是:426
输入第1个数
3
输入第2个数
123
输入第3个数
21
和是:583
输入第1个数
34

  

原文地址:https://www.cnblogs.com/langlove/p/3407748.html