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

📄 average1.java

📁 一个JAVA程序,可以对用户输入的几个数字 求其平均数
💻 JAVA
字号:
// Fig. 4.7: Average1.java
// Class-average program with counter-controlled repetition.
import javax.swing.JOptionPane;

public class Average1 {

   public static void main( String args[] )
   {
      int total; // sum of grades input by user
      int gradeCounter; // number of grade to be entered next
      int grade; // grade value
      int average; // average of grades

      String gradeString; // grade typed by user

      // initialization phase
      total = 0; // initialize total
      gradeCounter = 1; // initialize gradeCounter

      // processing phase
      while ( gradeCounter <= 10 ) {  // loop 10 times

         // prompt for input and read grade from user
         gradeString = JOptionPane.showInputDialog( "Enter integer grade: " );

         // convert gradeString to int
         grade = Integer.parseInt( gradeString );

         total = total + grade; // add grade to counter
         gradeCounter = gradeCounter + 1; // increment counter

      } // end while  

   // terminate phase
   average = total / 10; // integer division

   // display average of exam grades
   JOptionPane.showMessageDialog( null, "Class average is " + average,             "Class average", JOptionPane.INFORMATION_MESSAGE );
  
   System.exit( 0 ); // terminate the program
   
   } // end main

} // end class Average1

⌨️ 快捷键说明

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