zero100.java
来自「Java 入门书的源码」· Java 代码 · 共 33 行
JAVA
33 行
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.
/* Computes the sum of test scores between
* zero and 100. The program asks the user if
* another score is available, and if so reads it,
* adding scores in the reand to the total so far.
* If no more scores are available, the program
* displays the total.
*/
import iopack.Io;
public class Zero100 {
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");
if (score >= 0 && score <= 100)
total += score;
else
System.out.println(" " + score + " is not between zero and 100");
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 + -
显示快捷键?