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

📄 assigngrade.java

📁 JAVA程序设计导论那本书上的一些源代码. 在学那本书的下来的
💻 JAVA
字号:
import javax.swing.JOptionPane;public class AssignGrade {  /** Main method */  public static void main(String[] args) {    int numberOfStudents = 0; // The number of students    int[] scores; // Array scores    int best = 0; // The best score    char grade; // The grade    // Get number of students    String numberOfStudentsString = JOptionPane.showInputDialog(      null, "Please enter number of students:",      "Example 5.2 Input", JOptionPane.QUESTION_MESSAGE);    // Convert string into integer    numberOfStudents = Integer.parseInt(numberOfStudentsString);    // Create array scores    scores = new int[numberOfStudents];    // Read scores and find the best score    for (int i = 0; i < scores.length; i++) {      String scoreString = JOptionPane.showInputDialog(null,        "Please enter a score:",        "Example 5.2 Input", JOptionPane.QUESTION_MESSAGE);      // Convert string into integer      scores[i] = Integer.parseInt(scoreString);      if (scores[i] > best)        best = scores[i];    }    // Declare and initialize output string    String output = "";    // Assign and display grades    for (int i = 0; i < scores.length; i++) {      if (scores[i] >= best - 10)        grade = 'A';      else if (scores[i] >= best - 20)        grade = 'B';      else if (scores[i] >= best - 30)        grade = 'C';      else if (scores[i] >= best - 40)        grade = 'D';      else        grade = 'F';      output += "Student " + i + " score is " +        scores[i] + " and grade is " + grade + "\n";    }    // Display the result    JOptionPane.showMessageDialog(null, output,      "Example 5.2 Output", JOptionPane.INFORMATION_MESSAGE);  }}

⌨️ 快捷键说明

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