代码的书写规范很重要。
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int game_num = (int) (Math.random() * 100)+1;
- // System.out.println(game_num);//查看是是否是1-100 随机数
- System.out.println("请输入一个1-100的数字");
- int count = 1;
- boolean GAME_OVER = false;
- while (!GAME_OVER) {
- int num = scanner.nextInt();
- if (num < game_num) {
- System.out.println("您输入的数小了");
- count++;
- } else if (num > game_num) {
- System.out.println("您输入的数大了");
- count++;
- } else {
- System.out.println("恭喜您猜中了!");
- System.out.println("您一共用了" + count + "次");
- return;
- }
- }
- scanner.close();
- }
复制代码 |
|