周小宝爱学习
2016-06-01 20:04
请教哪里有错 如果没错为何会输出两遍“循环抛出异常了!”?
package com.imooc;
public class TryCatchFinallyTest {
public int test(){
int divider = 10,result = 100;
try{
while(divider > -1){
divider --;
result = result + 100/divider;
}
return result;
}catch(Exception e){
System.out.println("循环抛出异常了!");
return -1;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
TryCatchFinallyTest tcft = new TryCatchFinallyTest();
tcft.test();
System.out.println("程序执行完毕,最后的结果result=" + tcft.test());
}
}
哦 我知道了 我调用了两次tcft.test(); 我很蠢。尴尬。。。
Java入门第三季
409767 学习 · 4530 问题
相似问题