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

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

異常問題,求幫忙

public int selectServer(){

int choose=0;

try{

choose = input.nextInt(); ?

if(choose<1||choose>6)

throw new Exception();

return choose;

} catch (InputMismatchException e){

System.out.println("輸入格式不正確,請(qǐng)重新正確數(shù)字:");

input.nextLine();

selectServer();

} catch (Exception e) {

System.out.println("請(qǐng)輸入正確數(shù)字(1~6):");

input.nextLine();

selectServer();

}

return choose;

}

第一次輸入錯(cuò)誤拋出異常之后,重新輸入正確的數(shù)但是返回值不正確

正在回答

5 回答

public static void selectServer(){
int choose=0;
input = new Scanner(System.in);
try{
choose = input.nextInt();?
if(choose<1||choose>6){
throw new Exception();
}
System.out.println("final =" + choose);
} catch (InputMismatchException e){
System.out.println("輸入格式不正確,請(qǐng)重新正確數(shù)字:");
input.nextLine();
selectServer();
} catch (Exception e) {
System.out.println("請(qǐng)輸入正確數(shù)字(1~6):");
input.nextLine();
selectServer();
}

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

具體參考線的代碼

public?static?void?selectServer(){
int?choose=0;
input?=?new?Scanner(System.in);
try{
choose?=?input.nextInt();??
if(choose<1||choose>6){
throw?new?Exception();
}?
System.out.println("final?="?+?choose);
}?catch?(InputMismatchException?e){
System.out.println("輸入格式不正確,請(qǐng)重新正確數(shù)字:");
input.nextLine();
selectServer();
}?catch?(Exception?e)?{
System.out.println("請(qǐng)輸入正確數(shù)字(1~6):");
input.nextLine();
selectServer();
}

}


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

因?yàn)槟爿斎脲e(cuò)誤數(shù)據(jù)的時(shí)候,直接去selectServer(),沒有 結(jié)束當(dāng)前的線程,后面還有return choose,所有你第一次輸入的數(shù)據(jù)會(huì)在第二次打印出來

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

王明曉 提問者

要怎么才能結(jié)束當(dāng)前線程啊
2016-08-05 回復(fù) 有任何疑惑可以回復(fù)我~

這個(gè)函數(shù),你每次出錯(cuò)之后,都輸入一個(gè)數(shù)字,然后在重新執(zhí)行selectServer(),又把choose置0 ,所以,,,,,你可以把那句話去掉試試

ps:新手,懂得不多。

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

王明曉 提問者

但是重新執(zhí)行selectServer(),choose重置為0之后會(huì)繼續(xù)讓控制臺(tái)輸入一個(gè)choose給它賦值,應(yīng)該會(huì)覆蓋啊
2016-08-05 回復(fù) 有任何疑惑可以回復(fù)我~

666


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

舉報(bào)

0/150
提交
取消
Java入門第二季 升級(jí)版
  • 參與學(xué)習(xí)       531095    人
  • 解答問題       6276    個(gè)

課程升級(jí)!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙

進(jìn)入課程

異常問題,求幫忙

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

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

幫助反饋 APP下載

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

公眾號(hào)

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