为什么我用搜狗输入图书名称以后经常卡住不能重新运行

来源:1-9 经验总结

走在_路上

2015-08-05 16:56

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();
}
 
}
 
}

 

写回答 关注

1回答

  • 伊兮尘昔
    2015-08-05 18:04:48

    卡住的截图还有报错信息发一下呗?要不咋给你解决

Java入门第三季

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

409764 学习 · 4543 问题

查看课程

相似问题