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

📄 scoresum.java

📁 Java 入门书的源码
💻 JAVA
字号:
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.

              /*  Uses a while loop to compute the sum of 
               *  test scores.  The program asks the user if
               *  another score is available, and if so adds 
               *  that score to the total so far.  If not, the program
               * displays the total
               */

import iopack.Io;
public class ScoreSum {
  public static void main(String [] args) {
    int score;            // holds current score
    int answer;           // 1 if another score
                          // 0 if no more scores
    int total = 0;        // sum of scores so far
    answer = Io.readInt("Enter 1 to enter score, 0 to quit");
    while (answer == 1) {
      score = Io.readInt("Enter the score");
      total += score;
      answer = Io.readInt("Enter 1 to enter score, 0 to quit");
    }
    System.out.println("The total is " + total);
    Io.readString("Press any key to exit");   // Added for IDE use
  }
}   

⌨️ 快捷键说明

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