打了個(gè)簡(jiǎn)單的處理異常,出現(xiàn)了點(diǎn)疑惑,求幫助!
?
package One;
import java.util.Scanner;
public class Thorwable {
?public static void main(String[] args){
??int num = 0;
??Scanner input=new Scanner(System.in);
??try{
???System.out.println("輸入一個(gè)整數(shù)來測(cè)試異常: ");
??? num=input.nextInt();
??}catch(Exception a){
???System.out.println("請(qǐng)輸入一個(gè)整數(shù)!");
??? num = input.nextInt();
??}finally{
???System.out.println("整數(shù)為: "+num);
??}
??
?}
}
為什么檢測(cè)到異常后不能再次輸入?
2016-07-08
import java.util.Scanner;
public class dd {
?public static void main(String[] args){
? int num = 0;
? Scanner input=new Scanner(System.in);
? try{
? ?System.out.println("輸入一個(gè)整數(shù)來測(cè)試異常: ");
? ?num=input.nextInt();
? }catch(Exception a){
? ?Scanner b=new Scanner(System.in);
? ?System.out.println("請(qǐng)輸入一個(gè)整數(shù)!");
? ? num = b.nextInt();
? }finally{
? ?System.out.println("整數(shù)為: "+num);
? }
??
?}
}
2016-08-05
為什么你的catch(Excepetion a)中Exception后面是a呢?
2016-07-08
你的提示輸入就一個(gè),所以執(zhí)行一次后就沒辦法執(zhí)行輸入了
2016-07-04
nextInt()就讀一次不會(huì)讀取下面的內(nèi)容,改成next()即可。