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

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

這個代碼完全一摸一樣,為什么代碼finally后面的syso不執行了


package com.imooc.test;


import javax.naming.spi.DirStateFactory.Result;


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 result2 = tct.test();//tct是TryCatchTest類的新建實例化對象

? ? ? ? System.out.println("我想大聲告訴你,test2()方法執行完畢!返回值為:");

? ? ??

? ? }

? ? 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;

? ? ? ? }

? ? ? ??

? ? }

? ? public int test2(){

? ? ? ? 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 result=999;

? ? ? ? }finally {

? ? ? ? ? ?

? ? ? ? ? ? System.out.println("這是finally,哈哈");

? ? ? ? ? ? System.out.println("我是result,我的值是"+result);

? ? ? ? }

? ? }

}


正在回答

1 回答

你函數調用寫錯了,main方法的第二個調用應該是test2()。

3 回復 有任何疑惑可以回復我~
#1

qq_慕婉清0460615 提問者

謝謝,我先看看
2020-04-29 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

這個代碼完全一摸一樣,為什么代碼finally后面的syso不執行了

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

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

幫助反饋 APP下載

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

公眾號

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