scoresum.java
来自「Java 入门书的源码」· Java 代码 · 共 28 行
JAVA
28 行
//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 + =
减小字号Ctrl + -
显示快捷键?