在catch塊中捕獲異常后,怎么回到try塊中重新執行try塊中的代碼?
try {
System.out.println("*****歡迎使用租車系統*****");
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("請輸入正確數字!");
}
想實現一個重新輸入正確數字的功能
2021-12-20
可以在try/catch結構外面套用一層while循環,try中的業務邏輯執行完break;出現異常進入catch則進行循環
2020-03-25
首先應該把第一句歡迎和后面的代碼分別放在兩個方法中,然后在catch里面打印輸出后加上 input = new Scanner(System.in); 刷新輸入值,再返回這個方法,例如第二個方法叫choice();就寫個choice();
2020-03-22
你當前是如何調用這個程序的,就把調用方法寫在catch的代碼塊中。