import java.util.Scanner;
class Guess {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个整数,范围在1-100:");
int i = (int)(Math.random() * 100) + 1;
while (true){ //因为要猜很多次,所以要无限循环
int s = sc.nextInt();
if (s > i ){
System.out.println("大了");
} else if (s < i){
System.out.println("小了");
}else {
System.out.println("中了");
break;
}
}
}
}
|
|