⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calculategrade.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -