junwei_tang
2018-09-15 16:27
package com.imooc.books;
import java.util.Scanner;
public class books {
public static void main(String[] args){
String[] books = {
"高数","语文","英语","政治"
};
Scanner input = new Scanner(System.in);
System.out.println("******图书查询系统******");
while(true){
try{
System.out.println("输入命令:1-按照名查找图书;2-按照序号查找图书;3-退出");
int x = input.nextInt();
if(x == 1){
String bookName = input.next();
for(int i = 0;i < books.length;i++){
if(bookName.equals(books[i])){
System.out.println("book:" + books[i]);
break;
}
if(i == books.length-1)
System.out.println("您查找的图书不存在,请重新输入");
}
}
else if(x == 2){
int number = input.nextInt();
if(number <= books.length){
System.out.println("book:" + books[number-1]);
}
else{
System.out.println("您查找的图书不存在,请重新输入");
}
}
else if(x == 3){
System.out.println("Bye!");
break;
}
else{
System.out.println("输入有误请根据提示输入数字");
}
}catch(Exception e){
System.out.println("命令输入错误!");
input.nextLine();
continue;
}
}
}
}
好像没有异常抛出把?
666
Java入门第三季
409768 学习 · 4463 问题
相似问题