課程
/后端開發(fā)
/Java
/Java入門第三季
這段代碼是干什么用的,蠻復(fù)雜的
2015-10-17
源自:Java入門第三季 1-3
正在回答
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()方法執(zhí)行,返回值:"+result);
int result2=tct.test2();
System.out.println("test2執(zhí)行完畢 ");
}
/**
* divisor(除數(shù)):
* result(結(jié)果):
* try-catch捕獲循環(huán)
* 每次循環(huán),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("循環(huán)拋出異常");
return-1;
* 如果捕獲異常,打印輸出 “拋出異常”,返回result=999
* finally:打印輸出“這是finally”,同時(shí)打印result的值
public int test2(){
return result=999;
}finally{
System.out.println("這是finally ");
System.out.println("result:"+result);
? }
太空人
視頻的代碼,我看不出來(lái)是干什么的
確實(shí)蠻復(fù)雜的.....問(wèn)題是代碼在哪里............
舉報(bào)
Java中你必須懂得常用技能,不容錯(cuò)過(guò)的精彩,快來(lái)加入吧
2 回答請(qǐng)問(wèn)這代碼是什么的 用來(lái)干嘛的
1 回答視頻中這段代碼有什么用?
3 回答這段代碼什么意思呢?
3 回答我想知道prefix.equals(".java")這段代碼中prefix的作用是什么,以及它的用法
3 回答這段代碼直接復(fù)制到eclipse里會(huì)報(bào)錯(cuò)!
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-10-17
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()方法執(zhí)行,返回值:"+result);
int result2=tct.test2();
System.out.println("test2執(zhí)行完畢 ");
}
/**
* divisor(除數(shù)):
* result(結(jié)果):
* try-catch捕獲循環(huán)
* 每次循環(huán),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("循環(huán)拋出異常");
return-1;
}
}
/**
* divisor(除數(shù)):
* result(結(jié)果):
* try-catch捕獲循環(huán)
* 每次循環(huán),divider減一,result=result+100/divider
* 如果捕獲異常,打印輸出 “拋出異常”,返回result=999
* 否則,返回result
* finally:打印輸出“這是finally”,同時(shí)打印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("循環(huán)拋出異常");
return result=999;
}finally{
System.out.println("這是finally ");
System.out.println("result:"+result);
}
? }
}
2015-10-17
視頻的代碼,我看不出來(lái)是干什么的
2015-10-17
確實(shí)蠻復(fù)雜的.....問(wèn)題是代碼在哪里............