哥们,我帮你修改了一下if语句,你看一下是不是更合理了
- import java.util.Scanner;
- class Test1_guessNum {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in); //创建键盘录入对象.
- System.out.println("请从键盘输入你所猜的数,范围在1-100之间: ");
- int count = 0;
- int num = (int)(Math.random() * 100) + 1;
- while (true) {
- int guessNum = sc.nextInt();
- if (guessNum > 100 || guessNum < 1) {
- System.out.println("哥们你是不是不识字,范围在1-100之间!");
- System.out.println("请从键盘输入你所猜的数,范围在1-100之间: ");
- continue;
- }
- count ++;
- if (guessNum > num) {
- System.out.println("大了");
- }else if (guessNum < num) {
- System.out.println("小了");
- }else {
- System.out.println("恭喜你,猜中了!");
- break;
- }
- }
- if (count > 0 && count <= 3) {
- System.out.println("大人真乃神人也!");
- }else if (count > 3 && count <= 10) {
- System.out.println("大人的智商还有待提高!");
- }else {
- System.out.println("大人,地球不适合你了,请你回火星吧!");
- }
- }
- }
复制代码
|