Java二维数组实现学生成绩存储

package practice;

import java.util.Scanner;

public class ScoreReceiveAndOutput {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int scoreArr[][] = new int[2][3];
		// 循环接收2个班3位同学的成绩
		for (int i = 0; i < scoreArr.length; i++) {
			System.out.println("----------No.0" + (i + 1) + "班----------");
			for (int j = 0; j < scoreArr[i].length; j++) {
				System.out.print("请输入第" + (j + 1) + "个成绩:");
				scoreArr[i][j] = sc.nextInt();
			}
			System.out.println();
		}

		System.out.println("----------班级总分----------");
		for (int i = 0; i < scoreArr.length; i++) {
			int sum = 0; // 循环声明对应班级数量的总分累加器
			for (int j = 0; j < scoreArr[i].length; j++) {
				sum += scoreArr[i][j];
			}
			System.out.println("No.0" + (i + 1) + "班学生的总成绩为:" + sum);
		}

		sc.close();

	}

}

你可能感兴趣的:(典化成籍-Java)