import java.util.Random;
import java.util.Scanner;
class Demo2_Work {
public static void main(String[] args) {
Random r = new Random();
int guessNum = r.nextInt(101);
Scanner sc = new Scanner(System.in);
System.out.println("请输入0到100整数");
while (true) {
int result = sc.nextInt();
if (result > guessNum) {
System.out.println("大了");
}else if (result < guessNum) {
System.out.println("小了");
}else {
System.out.println("中了");
break;
}
}
}
}这是用RONDOM类做的,更好店 |