大神帮看看代码
package borrowbook;
import java.util.Scanner;
/**
*
* @author lenovo
*/
public class BorrowBook {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int[] bookNum= {1,2,3,4};
String[] bookName={"java","C++","E"};
System.out.println("请输入命令:1-按序号查找图书;2-按书名查找图书");
Scanner input=new Scanner(System.in);
int a;
try{
a=input.nextInt();
xunhuan1:
if(a==1){
System.out.println("请输入图书序号:");
int num=input.nextInt();
System.out.println("book:"+bookName[num-1]);
}else if(a==2){
System.out.println("请输入书名:");
String name=input.next();
for(int i=0;i<bookName.length;i++){
//System.out.println(bookName[i]);
if(bookName[i].equals(name)){
System.out.println("book:"+bookName[i]);
break xunhuan1;
}
}
System.out.println("该书不存在");
}else{
System.out.println("请输入1或2");
}
}catch(Exception e){
System.out.println("指令类型不正确,请重新输入");
}
}
}