為什么我用搜狗輸入圖書名稱以后經??ㄗ〔荒苤匦逻\行
import java.util.InputMismatchException;
import java.util.Scanner;
public class Book {
?public String books[][]={{"物理","化學","歷史","政治"},{"1","2","3","4"}};
?public static void main(String[] args) {
??Book Use=new Book();
??Use.test();
??
??
?}
public void test(){
Scanner input=new Scanner(System.in);
System.out.println("輸入命令:1-按照名稱查找圖書;2-按照序號查找圖書");
try{
?int a=input.nextInt();
?switch(a){
?case 1:
? System.out.println("請輸入圖書名稱");
? String name=input.next();
??? for(int i=0;i<books[0].length;i++){
????? if(name.equals(books[0][i])){?
???? ?System.out.println("book:"+books[0][i]);
???? ?test();
????? }
??? }
???? ? System.out.println("圖書不存在,請重新輸入");
?test();
???
?case 2:
??System.out.println("請輸入圖書序號");
??try{
??int d=input.nextInt();
??for(int i=0;i<books[1].length;i++){
???if(d==i+1){
???System.out.println("book"+books[0][i]);?
???}
??}
??test();
??}catch(InputMismatchException d ){
???System.out.println("輸入有誤,請輸入正確的圖書序號");
???test();
??}
?
?}
?
}catch(Exception e){
?System.out.println("命令輸入錯誤!請根據提示輸入數字命令");
?test();
}
?
}
?
}
?
2015-08-05
卡住的截圖還有報錯信息發一下唄?要不咋給你解決