關于try.catch語句和if、swtich語句的嵌套
比方說只想要用try.catch檢驗switch語句中的一部分,如:
????????????????try?{
int?opt1?=?input.nextInt();
}?catch?(InputMismatchException?e)?{
e.printStackTrace();
}
switch?(opt1)?{
//……
}最后switch中的opt1無法調用,顯示無有效變量
請問如何解決?
2015-06-29
int c=opt1;
2015-06-30
java中{}即為作用域