import java.util.Scanner;
class GuessGame {
public static void main(String[] args) {
int num = (int)(Math.random() * 100) + 1;
//System.out.println(num);
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个整数,范围在1~100之间:");
while(true) {
int guess = sc.nextInt();
if (i>num) {
System.out.println("大了,请再试一次");
}
else if (i < num) {
System.out.println("小了,请再试一次");
}
else if (i == num) {
System.out.println("猜对了!");
break;
}
else {
System.out.println("输入无效,请重新输入");
}
}
}
} |
|