第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

不明白,為什么輸入a值為整數(shù)值,也會(huì)報(bào)異常?求指教啊

package test.Exception;
/*異常拋出及處理:try? catch? finally
?*
?*/
import java.util.*;
public class Exception_Test1 {

?? ?public static void main(String[] args) {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?Exception_Test1 Test =new Exception_Test1();
?? ??? ?int result =Test.test();
?? ??? ?System.out.println("test()方法執(zhí)行了,結(jié)果為:"+result);
?? ??? ?

?? ?}
?? ?public int test(){
?? ??? ?Scanner input =new Scanner(System.in);
?? ??? ?try{
?? ??? ??? ?int b =100;
?? ??? ??? ?System.out.println("請(qǐng)輸入a的值");
?? ??? ??? ?int a =input.nextInt();
??????????? while(a >-1){
?????????? ??? ?b = a+b/a;
?????????? ??? ?a--; ??? ?
??????????? }
??????????? return b;
?? ??? ?}catch(Exception e){
?? ??? ??? ?e.printStackTrace();
?? ??? ??? ?System.out.println("異常報(bào)出,a應(yīng)該為整數(shù)值");
?? ??? ??? ?return 0;
?? ??? ?}
?? ??? ?
?? ?}

}

正在回答

1 回答

?while(a >-1){
?????????? ??? ?b = a+b/a;
?????????? ??? ?a--; ??? ?
??????????? }

這個(gè)循環(huán),只要a>-1就循環(huán),a--,那么不論你輸入啥,總會(huì)走到a=0的時(shí)候,0不能作為分母啊,會(huì)導(dǎo)致?b = a+b/a;

b無窮大,肯定報(bào)異常了啊,你可以把判斷條件改成 a>0

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

ygKan 提問者

了解。謝謝
2019-04-28 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

不明白,為什么輸入a值為整數(shù)值,也會(huì)報(bào)異常?求指教啊

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)