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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我在 Java 中使用 while 循環、if_else 和 try_catch 與掃描器語句并

我在 Java 中使用 while 循環、if_else 和 try_catch 與掃描器語句并

開滿天機 2023-09-27 16:23:39
嘗試接受 [0,1,2,3,4] 范圍內的用戶輸入,直到他輸入有效數字。使用try-catch修復異常錯誤   boolean good = true;   int x = reader.nextInt();    while (good != false) {    try {        if (x > launchEventList.size()-1) {            System.out.println("Please provide a valid input");            reader.nextInt();        } else {              System.out.println("\nDetails of event on index "+ x + " are ==>> " + getLe(x));            good = false;        }    }    catch (IndexOutOfBoundsException e) {        System.out.println("Invalid Input");    }
查看完整描述

1 回答

?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

在 if 語句中存儲reader.nextInt()變量 x。

x=reader.nextInt();


查看完整回答
反對 回復 2023-09-27
  • 1 回答
  • 0 關注
  • 75 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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