TryCatchTest那一行報錯,請問是什么問題?
public static void main(String[] args) {
//新建一個TryCatchTset類的實例
TryCatchTest tct=new TryCatchTest();?//這一行不知道出了什么問題,前面有報錯的小標(biāo)記
int result=tct.test();
System.out.println("test()方法執(zhí)行完畢!返回值為:"+result);
}
? ? public int test(){
? ? int divider=10;
? ? int result=100;
? ? try {
? ? while(divider>-1) {
? ? divider--;
? ? result=result+100/divider;
? ? }
? ? return result;
? ? }catch (Exception e) {
? ? //打印出異常的具體信息
? ? e.printStackTrace();
? ? System.out.println("循環(huán)拋出異常了!!");
? ? return -1;
? ? }
?? ?
? ? }
2021-06-11
說錯了沒有錯呀
2021-06-11
括號問題main方法的括號不能把你寫的代碼包進(jìn)去
2020-02-01
如果你用的是eclipse,你可以把鼠標(biāo)移過去,然后它會顯示這個錯誤原因和解決方案。提示的如果是紅色的?,我還真不知道什么原因,如果是黃色的,可能是對象沒有被使用之類的
2020-01-28
沒有錯,你重新跑一下試試。
2020-01-25
報錯的那行,類名寫錯了。TestTryCatch? ? 還是TryCatchTest