作业中序号查找时输入字母报错后咋回到最开始处理方法了
package jieche;
import java.util.*;
public class jieshu {
static String d[]={"数学","化学"};
public static void step1(){
try{
System.out.println("请输入指令:1.按名字查找图书 2.按序号查找图书");
Scanner number=new Scanner(System.in);
int b=number.nextInt();
if(b==1){
find1();
}
else if(b==2){
find2();
}else{
System.out.println("输入异常,请输入数字1或2");
}
}catch(Exception e){
System.out.println("输入异常,请输入数字");
}
}
public static void find1(){
System.out.println("请输入书名");
Scanner number=new Scanner(System.in);
String c=number.next();
for(int i=0;i<2;i++){
if(d[i].equals(c)){
System.out.println("bool:"+c);
}
else{
System.out.println("没有此书");
}
}
}
public static void find2(){
System.out.println("请输入序号");
Scanner number=new Scanner(System.in);
int m=number.nextInt();
try{if(m>1){
System.out.println("没有此书");
}else{
System.out.println("book:"+d[m]);
}
}catch(NumberFormatException j){
System.out.println("输入异常,请输入数字序号");
}finally{
find2();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=1;
Scanner number=new Scanner(System.in);
while(a==1){
try{
step1();
}catch(Exception e){
System.out.println("输入异常");
}
}
}
}