不斷收到語法錯誤,插入while表達式來完成do語句。它也許一些簡單的像大括號等我的代碼有什麼問題?盡力而爲嘗試抓住
{
int num = 0;
//flag
boolean inputOk = false;
Scanner s = new Scanner (System.in);
do {
try {
System.out.println("Enter a number....");
num =s.nextInt();
System.out.println("you entered : " + num);
// got here then things are good
inputOk = true;
} catch (InputMismatchException ex) {
System.out.println("Again please....digits only");
// flush the scanner
s.next();
}
} while (inputOk != true);
s.close();
System.out.println("Thank you");
}
什麼是錯誤? –
請檢查以下解決方案我認爲{是唯一的問題 –
請標記爲答案或投票了此解決方案幫助您 –