package?booksystem;
import?java.util.*;
public?class?BookSystem?{
String?book[]={"平凡的世界","高等數學","C程序設計"};
Scanner?input=new?Scanner(System.in);
public?static?void?main(String[]?args)?{
BookSystem?begin=new?BookSystem();
begin.welcome();
}
public?void?welcome(){
System.out.println("輸入命令:1-按照名稱查找圖書;2-按照序號查找圖書;");
try{
int?select=input.nextInt();
if(select==1)
this.searchName();
else?if(select==2)
this.searchNum();
else?throw?new?Exception();
}catch(Exception?e){
System.out.println("請輸入正確的指令");
input.nextLine();?//跳過錯誤類型
this.welcome();?
}
}
public?void?searchName(){
System.out.println("請輸入圖書名稱:");
String?bookname=input.next();
System.out.println(bookname);
Boolean?flag=false;
for(int?i=0;i<book.length;i++)
if(bookname.equals(book[i]))
flag=true;
if(flag)
System.out.println("圖書:"+bookname);
else?System.out.println("圖書不存在");
this.welcome();
}
public?void?searchNum(){
System.out.println("請輸入圖書序號:");
int?num=input.nextInt();
if(num<=book.length)
System.out.println("圖書:"+book[num-1]);
else?System.out.println("圖書不存在");
this.welcome();
}
}
2015-02-08
同學,請問你有什么問題嗎?還是要保存代碼,如果是保存代碼我們是有專門的筆記可以保存代碼的!
2015-12-27
三個方法能用繼承來完成嗎?
2015-04-18
?為什么只有這個方法要用跳過錯誤類型?
input.nextLine();?//跳過錯誤類型
2015-03-27
小白問下,
for(int?i=0;i<book.length;i++)
????????????if(bookname.equals(book[i]))
????????????????flag=true;
這段代碼當IF判斷語句為真時,true賦值給flag,for循環是否應該跳出,不再執行
2015-03-21
this.welcome是什么意思啊????????