score.java
来自「Java 入门书的源码」· Java 代码 · 共 34 行
JAVA
34 行
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.
/* Uses nested if-else statements
* to choose among alternatives
* to assign letter grades to test scores.
* Terminate input with a negative value
* used as a sentinel.
*/
import iopack.Io;
public class Score {
public static void main(String [] args) {
int score = Io.readInt("Enter a test score or -1 to quit");
while (score >= 0) {
if (score < 50)
System.out.println("Score " + score + " receives an F");
else if (score >= 50 && score < 60)
System.out.println("Score " + score + " receives a D");
else if (score >= 60 && score < 80)
System.out.println("Score " + score + " receives a C");
else if (score >=80 && score < 90)
System.out.println("Score " + score + " receives a B");
else if (score >= 90 && score <= 100)
System.out.println("Score " + score + "receives an A");
else
System.out .println
("Score can't be greater than 100, try again");
score = Io.readInt("Enter a test score or -1 to quit");
}
Io.readString("Press any key to exit"); // Added for IDE use
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?