分支结构练习-3.switch结构判断成绩

来源:互联网 发布:网络邮箱广告投放 编辑:程序博客网 时间:2024/05/23 18:32

3、switch结构判断成绩

90-100 A
80-89 B
70-79 C
60-69 D
<60 E
使用switch结构

代码如下:

public class Score {    public static void main(String[] args) {        // TODO Auto-generated method stub        while (true) {            System.out.println("请输入分数:");            Scanner sc = new Scanner(System.in);            double score = sc.nextDouble();            int c = (int) (score / 10);            switch (c) {                case 10:                case 9: {                    System.out.println("A");                    break;                }                case 8:                    System.out.println("B");                    break;                case 7:                    System.out.println("C");                    break;                case 6:                    System.out.println("D");                    break;                default:                    System.out.println("E");                    break;            }        }    }}
0 0
原创粉丝点击