二维列表简单练习
这个代码的缺点就是虽然绘只出超分了但是不能自动更正为100,希望大佬指点
package day10;
import java.util.Scanner;
public class Workstudent {
public static void main(String[] args) {
// 1. 班上有3个学生,每个学生都参加了三门功课的考试,其中第 生,上
级要求给他每门功课都+5【要求:使用二维数组做,并且分别使用for循环和增强for 循环遍历二维数组】
Scanner scan = new Scanner(System.in);
System.out.print("请输入总共多少名学生:");
int Student=scan.nextInt();
System.out.print("请输入总共几门功课考试:");
int exam=scan.nextInt();
double[][] scores = new double[Student][exam];
double score;
for (int i = 0; i < Student; i++) { //for( int i: Student ){}
for (int j = 0; j < exam; j++) {
while (true) {
System.out.println("请录入第" + (i + 1) + "名学生,第" + (j + 1) + "门课程成绩:");
score = scan.nextDouble();
scores[i][j] = score;
if (score >= 0 && score <= 100) {
if (i == (Student-2)||i==(Student-3)) {
score += 5.0;
scores[i][j] = score;
if (score > 100) {
scores[i][j] = 100;
scores[i][j] = score;
System.out.println("因为你是特长生,需要加五分,但由于满分为100分,所以你最多为100分");
}
}
break;
} else {
System.out.println("超出分数范围,请重新录入");
continue;
}
}
}
}
for (double[] ds : scores) {
for (double d : ds) {
System.out.println(d);
}
}
}
}