亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

test2()方法里的返回值是381

package com.imooc.test;

public class TryCatchTest {

?? ?public static void main(String[] args) {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?TryCatchTest tct=new TryCatchTest();
?? ??? ?int result=tct.test();
?? ??? ?System.out.println("test()方法執行完畢!返回值為:"+result);
?? ??? ?int result1=tct.test2();
?? ??? ?System.out.println("test2()方法執行完畢!"+result1);
?? ?}
?? ?/**
?? ? * test()方法說明:
?? ? * divider(除數)
?? ? * result(結果)
?? ? * try-catch補貨while循環
?? ? * 每次循環divider減一,result=result+100/divider
?? ? * 如果:捕獲異常,打印輸出"拋出異常了!!!",返回 -1
?? ? * 否則正確返回 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("循環拋出異常了!!!");
?? ??? ??? ?return -1;
?? ??? ?}
?? ?}
?? ??? ?/**
?? ??? ? * test2()方法說明:
?? ??? ? * divider(除數)
?? ??? ? * result(結果)
?? ??? ? * try-catch補貨while循環
?? ??? ? * 每次循環divider減一,result=result+100/divider
?? ??? ? * 如果:捕獲異常,打印輸出"拋出異常了!!!",返回 -1
?? ??? ? * 否則正確返回 result
?? ??? ? */
?? ??? ?public int test2(){
?? ??? ??? ?int divider=10;
?? ??? ??? ?int result1=100;
?? ??? ??? ?try {
?? ??? ??? ??? ?while(divider>-1){
?? ??? ??? ??? ??? ?divider--;
?? ??? ??? ??? ??? ?result1=result1+100/divider;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?return result1;
?? ??? ??? ?}catch (Exception e) {
?? ??? ??? ??? ?e.printStackTrace();
?? ??? ??? ??? ?System.out.println("循環拋出異常了!!!");
?? ??? ??? ??? ?return 999;
?? ??? ??? ?}finally{
?? ??? ??? ??? ?System.out.println("這是finally!!哈哈!");
?? ??? ??? ??? ?System.out.println("我是result!!我的值是:"+result1);
?? ??? ??? ?}?? ?
?? ??? ?}

?? ?
}

正在回答

2 回答

第58行代碼,return result = 999;

0 回復 有任何疑惑可以回復我~

http://img1.sycdn.imooc.com//581077e200013ae705830573.jpg


你們看我的值 居然是381

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第三季
  • 參與學習       409767    人
  • 解答問題       4543    個

Java中你必須懂得常用技能,不容錯過的精彩,快來加入吧

進入課程

test2()方法里的返回值是381

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號