关于try.catch语句和if、swtich语句的嵌套
比方说只想要用try.catch检验switch语句中的一部分,如:
try {
int opt1 = input.nextInt();
} catch (InputMismatchException e) {
e.printStackTrace();
}
switch (opt1) {
//……
}最后switch中的opt1无法调用,显示无有效变量
请问如何解决?