我有一個try-catch的小問題。從Try-Catch中獲取字符串
我的目標是讓test
和test2
的值超出我稍後可以使用的try塊。
如何處理?
public class MyApplication {
public static void main(String[] args) {
try {
int test = Integer.parseInt("123");
String test2 = "ABCD";
} catch (NumberFormatException ex) {
System.out.print(ex.getMessage());
}
}
}
您有範圍問題並將聲明移出嘗試。 –
在另一個範圍聲明,例如類 – XtremeBaumer
@terades:請爲用戶駱駝案例變量名稱。所有大寫字母都保留給最終變量/常量。 –