如果输入2要根据序号,为什么这个i++是dead code?任意输入一个非0整数并回车,为什么程序没有一点反应?
package com.imooc;
import java.util.Arrays;
import java.util.Scanner;
public class Library {
static Library test=new Library();
public static void main(String[] args) {
test.Lib();
}
String[] book= {"高数","Java","C","Python","C#","C++","Visual Basic","AI"};
public void Lib() {
System.out.println("输入命令:1,按照名称查找图书;2,按照序号查找图书");
Scanner input=new Scanner(System.in);
int num=input.nextInt();
try {
if(num==1) {
System.out.println("请输入图书名称");
Scanner input2=new Scanner(System.in);
String bookname=input2.next();
boolean status=Arrays.toString(book).contains(bookname);
if(status)
System.out.println("book:"+bookname);
else
throw new Error404Exception();
}else if(num==2) {
System.out.println("请输入图书序号(从0到7)");
Scanner input3=new Scanner(System.in);
int bookNum=input3.nextInt();
for(int i=0;i<=7;i++) {
if(bookNum==i)
System.out.println("book:"+book[i]);
break;
}
}else{
throw new Error691Exception();
}catch(Error404Exception e) {
System.out.println("错误404:抱歉,该图书不存在,请重新输入");
test.Lib();
}catch(Error691Exception e) {
System.out.println("错误691:输入错误,请重新输入");
test.Lib();
}
}
}