我正在做一个猜数字的游戏,并且我正在循环测试是否为int变量,但出于循环,它无法识别变量(抱歉,我的英语不好)
option = 1;
while (option == 1) {
System.out.print("from:");
Scanner input = new Scanner(System.in);
try {
int min = input.nextInt();
option ++;
}
catch (Exception e) {
System.out.println("only numbers...");
TimeUnit.SECONDS.sleep(2);
}
}
while (option == 2) {
System.out.print("to:");
Scanner input = new Scanner(System.in);
try {
int max = input.nextInt();
option ++;
}
catch (Exception e) {
System.out.println("only numbers...");
TimeUnit.SECONDS.sleep(2);
}
}
while (option == 3) {
System.out.print("number of lives:");
Scanner input = new Scanner(System.in);
try {
int lives = input.nextInt();
option ++;
}
catch (Exception e) {
System.out.println("only numbers...");
TimeUnit.SECONDS.sleep(2);
}
}
int number = (int) (Math.random()* max + min);
at“ int number =(int)(Math.random()* max + min);”说“ min无法解析为变量
-无法将max解析为变量”