averagefivenumbers.java

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

JAVA
28
字号
import javax.swing.*;
public class AverageFiveNumbers
{
  // This method calculates the average
  // of 5 user-entered numbers
  public static void main(String[] args)
  {
    final int MAXNUMS = 5;
    int count;
    double num, total, average;
    String s1;
    total = 0.0;
    for (count = 0; count < MAXNUMS; count++)
    {
      s1 =JOptionPane.showInputDialog("Enter a number:");
      num = Double.parseDouble(s1);
      total = total + num;
    }
    average = total / MAXNUMS;
  
    JOptionPane.showMessageDialog(null, 
               "The average of the data entered is " + average, 
               "Program 5.11", 
                JOptionPane.INFORMATION_MESSAGE);
    
    System.exit(0);  
  }
}

⌨️ 快捷键说明

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