A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© fanlelong 中级黑马   /  2016-4-3 18:22  /  711 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 fanlelong 于 2016-4-3 18:28 编辑

import java.util.Scanner;
class Text1Cheng {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);//创建一个键盘录入对象
                System.out.print("请输入一个1到100的整数:");
                int x = sc.nextInt();//将键盘录入的对象赋于x

                while (true) {
                        if (x>=90&&x<=100) {
                                System.out.println("优");
                                break;
                        }else if (x>=80&&x<=89) {
                                System.out.println("良");
                                 break;
                        }else if (x>=70&&x<=79) {
                                System.out.println("中");
                                break;
                        }else if (x>=60&&x<=69) {
                                System.out.println("及");
                                break;
                        }else if (x>=0&&x<=59) {
                                System.out.println("差");
                                break;
                        }else {
                                System.out.print("输入错误,请重新输入:");
                                x = sc.nextInt();
                        }
                }
        }
}
写的不知道对不对,老师讲的练习题目,自己改了下

1 个回复

倒序浏览
break是跳出循环的意思,switch里面如果没有break会case穿透
回复 使用道具 举报 1 0
您需要登录后才可以回帖 登录 | 加入黑马