studentscore.java

来自「Java 入门书的源码」· Java 代码 · 共 23 行

JAVA
23
字号
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.

/* Uses an array of arrays.
 * Computes the average score of
 * each student.
 */

import iopack.Io;
public class StudentScore {
  public static void main(String [] args) {
    int [][]student = {{52, 76, 65},{98, 87, 93},{43, 77, 62},{72, 73, 74}}; // scores
    double sum;                            // sum of the scores for each student
    for (int i=0; i<student.length; i++) {
      sum = 0; 
      for (int j=0; j<student[i].length; j++)  
        sum += student[i][j];
      System.out.print("The average score for student " + i + " is ");
      Io.println(sum/student[i].length,1);
    }
  }
} 
     

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?