package?immmmm;
import?java.util.Arrays;
import?java.util.Scanner;
public?class?YC?{
????public?static?void?main(String[]?args)?{
????????YC?a=new?YC();
????????a.zhu();
????}
????public?void?zhu()?{
????????String?sz[]?=?{"高數",?"數據結構",?"大學物理",?"java",?"網絡安全",?"沖啊少年",};
????????YC?rent?=?new?YC();
????????System.out.println("輸入命令:1—按照名稱查找圖書;2—按照序號查找圖書");
????????Scanner?got?=?new?Scanner(System.in);
????????int?x=got.nextInt();
????????try?{
????????????if?(x?==?1)?{
????????????????System.out.println("輸入圖書名稱:");
????????????????String?y?=?got.next();
????????????????boolean?status?=?Arrays.toString(sz).contains(y);
????????????????if?(status)?{
????????????????????System.out.println("book:"?+?y);
????????????????}?else?{
????????????????????throw?new?SMexception();
????????????????}
????????????}?else?if?(x?==?2)?{
????????????????System.out.println("輸入圖書序號:");
????????????????int?z?=?got.nextInt();
????????????????if?(z?>=?0?||?z?<=?sz.length)?{
????????????????????System.out.println("book:"?+?sz[z]);
????????????????}?else?{
????????????????????throw?new?zfexception();
????????????????}
????????????}?else?{
????????????????throw?new?Myexception();
????????????}
????????}?catch?(Myexception?e)?{
????????????System.out.println("命令輸入錯誤!請根據提示輸入數字!");
????????????rent.zhu();
????????}?catch?(SMexception?e)?{
????????????System.out.println("圖書不存在!");
????????????rent.zhu();
????????}?catch?(zfexception?e)?{
????????????System.out.println("圖書不存在!");
????????}
????}
}

2019-03-16