異常問題,求幫忙
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ù)但是返回值不正確
2016-10-05
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();
}
2016-08-16
具體參考線的代碼
2016-08-05
因?yàn)槟爿斎脲e(cuò)誤數(shù)據(jù)的時(shí)候,直接去selectServer(),沒有 結(jié)束當(dāng)前的線程,后面還有return choose,所有你第一次輸入的數(shù)據(jù)會(huì)在第二次打印出來
2016-08-05
這個(gè)函數(shù),你每次出錯(cuò)之后,都輸入一個(gè)數(shù)字,然后在重新執(zhí)行selectServer(),又把choose置0 ,所以,,,,,你可以把那句話去掉試試
ps:新手,懂得不多。
2016-08-05
666