Loading... <div class="panel panel-default collapse-panel box-shadow-wrap-lg"><div class="panel-heading panel-collapse" data-toggle="collapse" data-target="#collapse-ee409b1dbc01c2827c6cb40c740934b918" aria-expanded="true"><div class="accordion-toggle"><span style="">题目</span> <i class="pull-right fontello icon-fw fontello-angle-right"></i> </div> </div> <div class="panel-body collapse-panel-body"> <div id="collapse-ee409b1dbc01c2827c6cb40c740934b918" class="collapse in collapse-content"><p></p> ``` ◆输入一成绩,在控制台上输出其等级A/B/C/D/E 请输入成绩(Q/q退出): 86 B 请输入成绩(Q/q退出): 74 C 请输入成绩(Q/q退出): 120 超出范围(0-100),请重新输入! 请输入成绩(Q/q退出): 98 A 请输入成绩(Q/q退出): q bye! (提示:可用switch语句实现;屏幕输入用Scanner类) ``` <p></p></div></div></div> ## 代码 ``` public class Home { public static void main(String[] args) { int i = 1; while (i == 1){ System.out.println("请输入成绩(Q/q退出):"); Scanner sc = new Scanner(System.in); String input = sc.next(); switch (input){ case "q": case "Q": i = 0; System.out.println("bye!"); break; default: Double a = Double.valueOf(input); if (a>100){ System.out.println("超出范围(0-100),请重新输入!"); break; }else if (a>=90){ System.out.println("A"); break; }else if (a>=80){ System.out.println("B"); break; }else if (a>=70){ System.out.println("C"); break; }else if (a>=60){ System.out.println("D"); break; }else if (a>=0){ System.out.println("E"); }else { System.out.println("超出范围(0-100),请重新输入!"); break; } break; } } } } ``` 最后修改:2021 年 09 月 23 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 0 如果觉得我的文章对你有用,请随意赞赏