交作業(yè)(圖書查詢系統(tǒng))
package com.imooc.books;
import java.util.Scanner;
public class books {
public static void main(String[] args){
String[] books = {
"高數(shù)","語文","英語","政治"
};
Scanner input = new Scanner(System.in);
System.out.println("******圖書查詢系統(tǒng)******");
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("輸入有誤請根據(jù)提示輸入數(shù)字");
}
}catch(Exception e){
System.out.println("命令輸入錯誤!");
input.nextLine();
continue;
}
}
}
}
2018-12-11
好像沒有異常拋出把?
2018-09-17
666