calculategrade.java

来自「《A first book of java》by Gary J.Bronson 」· Java 代码 · 共 33 行

JAVA
33
字号
import javax.swing.*;
public class CalculateGrade
{
  public static void main(String[] args)
  {
    final int NUMGRADES = 4;
    final int NUMSTUDENTS = 20;
    int i,j;
    double grade, total, average;
    String s1;
    for (i = 1; i <= NUMSTUDENTS; i++)    // start of outer loop
    {
      total = 0;                 // clear the total for this student
      for (j = 1; j <= NUMGRADES; j++)   // start of inner loop
      {
        s1 = JOptionPane.showInputDialog(
                          "Enter an examination grade for this student:");
        grade = Double.parseDouble(s1);
  
        total = total + grade;   // add the grade into the total
      }                          // end of the inner for loop
      average = total / NUMGRADES;       // calculate the average
  
      JOptionPane.showMessageDialog(null, 
                                 "The average for student " + i + " is " + average,
                                 "Program 5.13", 
                                 JOptionPane.INFORMATION_MESSAGE);
    }     // end of the outer for loop
   
    System.exit(0);
  } 
}

⌨️ 快捷键说明

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