java通过使用“嵌套”FOR循环访问矩阵来填充ArrayList
使用挑战8中的矩阵和数组列表设计,创建一个数组总计,以保存5名学生的总分。通过使用“嵌套”FOR循环结构访问矩阵来填充ArrayList(i将移动,j将移动)。填写总数数组后,确定总数最高的学生的姓名,并说明他们的姓名和平均分数(小数点后1位)
如何将学生的总分从矩阵添加到ArrayList中的单个点
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<String> names = new ArrayList<String>();
ArrayList<Integer> total = new ArrayList<Integer>();
int [][] scores = new int [5][6];
int score = 0;
for (int i = 0; i < 5; i++) {
System.out.print("Enter " + "(" + (i+1) + ") friend's name: ");
names.add(input.nextLine());
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 6; j++) {
score = 1 + (int)(Math.random() * ((20 + 1)));
scores[i][j] = score;
}
total.add(i,0);
}
}
共 (0) 个答案