对用户输入的分数进行评级,其中,
分数在区间[90,100] ,等级评定为A
分数在区间[80,89]分,等级评定为B
分数在区间[70,79]分,等级评定为C
分数在区间[60,69]分,等级为D
60以下,等级评定为E。
要求输入分数必须是[0,100]之间的正整数。
根据上述软件需求的描述分析,运用等价类划分法划分等价类,包括测试用例。
public static void main(String[] args ) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(n >= 90)
System.out.println("A");
else if(n>= 80 && n<89)
System.out.println("B");
else if(n>= 70 && n<79)
System.out.println("C");
else if(n>= 60 && n<69)
System.out.println("D");
else
System.out.println("E");
}
这个还是比较容易的,建议去看下程序流程控制那一块。
这里呢不管是用if-elseif-···-else结构还是用switch-case结构都是可以解决的。
建议使用switch-case结构去写,会比较清晰
但凡你上课随便听点都能写。if else swith case