这段代码是干什么用的,蛮复杂的
package com.imooc.test;
public class TryCatchTest {
public static void main(String[] args) {
TryCatchTest tct=new TryCatchTest();
int result=tct.test();
System.out.println("test()方法执行,返回值:"+result);
int result2=tct.test2();
System.out.println("test2执行完毕 ");
}
/**
* divisor(除数):
* result(结果):
* try-catch捕获循环
* 每次循环,divider减一,result=result+100/divider
* 如果捕获异常,打印输出 “抛出异常”,返回-1
* 否则,返回result
* @return
*/
public int test(){
int divisor=10;
int result=100;
try{
while(divisor>-1){
divisor--;
result=result+100/divisor;
}
return result;
}catch(Exception e){
e.printStackTrace();
System.out.println("循环抛出异常");
return-1;
}
}
/**
* divisor(除数):
* result(结果):
* try-catch捕获循环
* 每次循环,divider减一,result=result+100/divider
* 如果捕获异常,打印输出 “抛出异常”,返回result=999
* 否则,返回result
* finally:打印输出“这是finally”,同时打印result的值
* @return
*/
public int test2(){
int divisor=10;
int result=100;
try{
while(divisor>-1){
divisor--;
result=result+100/divisor;
}
return result;
}catch(Exception e){
e.printStackTrace();
System.out.println("循环抛出异常");
return result=999;
}finally{
System.out.println("这是finally ");
System.out.println("result:"+result);
}
}
}
视频的代码,我看不出来是干什么的
确实蛮复杂的.....问题是代码在哪里............