在catch塊中捕獲異常后,怎么回到try塊中重新執(zhí)行try塊中的代碼?
try {
System.out.println("*****歡迎使用租車系統(tǒng)*****");
System.out.println("租車請輸入:1 退出請輸入:0");
System.out.print("請輸入:");
Scanner input=new Scanner(System.in);
int num=input.nextInt();
if(num==0) {
System.out.println("再見!");
return;
}
} catch (Exception e) {
System.out.println("請輸入正確數(shù)字!");
}
想實現(xiàn)一個重新輸入正確數(shù)字的功能
2021-12-20
可以在try/catch結(jié)構(gòu)外面套用一層while循環(huán),try中的業(yè)務(wù)邏輯執(zhí)行完break;出現(xiàn)異常進(jìn)入catch則進(jìn)行循環(huán)
2020-03-25
首先應(yīng)該把第一句歡迎和后面的代碼分別放在兩個方法中,然后在catch里面打印輸出后加上 input = new Scanner(System.in); 刷新輸入值,再返回這個方法,例如第二個方法叫choice();就寫個choice();
2020-03-22
你當(dāng)前是如何調(diào)用這個程序的,就把調(diào)用方法寫在catch的代碼塊中。