我正在尝试使用 try/catch。我非常确定语法是正确的,但不确定为什么会出现此错误:'(' expected catch^
这是我的代码:
Random first_number = new Random();
Random second_number = new Random();
int number_1;
int number_2;
int answer_M;
String answer;
int correctAnswer_M = 0;
for(int i=1;i<=20;i++)
{
try
{
number_1 = first_number.nextInt(10);
number_2 = second_number.nextInt(10);
System.out.print("\n " + i + ".) ");
System.out.print(number_1 + " multiplied by " + number_2 +" = ");
answer_M = Integer.parseInt(answer);
if(answer_M==(number_1 * number_2))
{
correctAnswer_M = correctAnswer_M + 1;
}
}
catch
{
System.out.print("Please enter an answer.");
i=i-1;
}
}
期待你的回复。谢谢!:)