package day1;
import java.util.Random;
import java.util.Scanner;
public class GuessNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();//获取随机数
int t = random.nextInt(1, 101);
while (true) {
System.out.print("请输入整数:");
int n = scanner.nextInt();//键盘输入的数字赋给n
if (n > t) {
System.out.printf("您猜的数有点大了%n");
} else if (n < t) {
System.out.printf("您猜的数有点小了%n");
} else {
System.out.println("恭喜您,猜对了");
break;
}
}
System.out.println("游戏结束");
}
}
while实现猜数字小游戏
最新推荐文章于 2024-08-30 18:40:43 发布