Java &引用;“无法解析输入”;当添加一个try..catch时
我最初试图让我的throw语句在没有try-catch和Java &引用;“无法解析输入”;当添加一个try..catch时,java,Java,我最初试图让我的throw语句在没有try-catch和userInput=input.nextInt()的情况下工作行运行良好。但是当我尝试添加try..catch时,它不喜欢我的输入,说它无法解析。我不认为我的尝试是正确的,但我正计划在我的输入得到认可后解决这个问题,但我也希望你能对你看到的反馈有所帮助 谢谢 import java.util.Scanner; public class Program6 { public static void main(
userInput=input.nextInt()的情况下工作代码>行运行良好。但是当我尝试添加try..catch时,它不喜欢我的输入,说它无法解析。我不认为我的尝试是正确的,但我正计划在我的输入得到认可后解决这个问题,但我也希望你能对你看到的反馈有所帮助
谢谢
import java.util.Scanner;
public class Program6
{
public static void main(String[] args)
{
final int NUMBER_HIGH_LIMIT = 100;
final int NUMBER_LOW_LIMIT = 10;
int userInput;
try
{
System.out.print("Enter a number between 10 and 100: ");
userInput = input.nextInt();//Says input cannot be resolved
Verify v = new Verify(NUMBER_HIGH_LIMIT, NUMBER_LOW_LIMIT);
}
catch(NumberHighException exception)
{
userInput = 0;
}
catch(NumberLowException exception)
{
userInput = 0;
}
}
}
您需要创建一个名为input
的扫描仪:
public class Program6 {
public static void main(String[] args) {
final int NUMBER_HIGH_LIMIT = 100;
final int NUMBER_LOW_LIMIT = 10;
int userInput;
try {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number between 10 and 100: ");
userInput = input.nextInt();//Says input cannot be resolved
Verify v = new Verify(NUMBER_HIGH_LIMIT, NUMBER_LOW_LIMIT);
} catch (NumberHighException exception) {
userInput = 0;
} catch (NumberLowException exception) {
userInput = 0;
}
}
}
您需要创建一个名为input
的扫描仪:
public class Program6 {
public static void main(String[] args) {
final int NUMBER_HIGH_LIMIT = 100;
final int NUMBER_LOW_LIMIT = 10;
int userInput;
try {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number between 10 and 100: ");
userInput = input.nextInt();//Says input cannot be resolved
Verify v = new Verify(NUMBER_HIGH_LIMIT, NUMBER_LOW_LIMIT);
} catch (NumberHighException exception) {
userInput = 0;
} catch (NumberLowException exception) {
userInput = 0;
}
}
}
在Java中使用变量之前,需要先声明变量。可能是他在添加try/catch时意外删除了带有声明的行。在Java中使用变量之前,需要声明变量。可能是他在添加try/catch时意外删除了带有声明的行。