匿名用户
1级
2010-08-25 回答
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class GradeManager {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader stdIn = new BufferedReader(new InputStreamReader(
System.in));
String inputStr = null;
double inputGrade = 0d;
do {
System.out.println("请输入成绩(0-100),输入y退出程序");
// 读入输入的成绩
inputStr = stdIn.readLine().trim();
if (inputStr.matches("\\d+.\\d+")) {
// 判断输入是否为数字
inputGrade = Double.parseDouble(inputStr);
if (inputGrade >= 0 && inputGrade <= 100) {
System.out.println(inputStr + " "
+ show((int) inputGrade));
}else{
System.out.println("请输入正确的成绩,正确的成绩在0-100之间的任意数字");
}
} else {
if (!inputStr.equalsIgnoreCase("Y")) {
// 输入不合法重新输入
System.out.println("请重新输入正确的成绩");
} else {
// 输入完毕
System.out.println("欢迎下次使用");
}
}
} while (inputStr != null && !inputStr.equalsIgnoreCase("Y"));
}
/**
*
* @param grade
* @return
*/
public static String show(int grade) {
String gradeLevel = "F";
switch (grade / 10) {
case 9:
gradeLevel = "A";
break;
case 8:
gradeLevel = "B";
break;
case 7:
gradeLevel = "C";
break;
case 6:
gradeLevel = "D";
break;
default:
gradeLevel = "F";
break;
}
return gradeLevel;
}
}