int guessNum = (int) (Math.random*100)+1;
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要猜的数字:1-100");
while(true) {
int num = sc.nextInt();
if(num>guessNum) {
System.out.println("大了");
} else if (num<guessNum) {
System.out.println("小了");
}else {
System.out.println("中了");
}
}
|
|