求助一下equals問題
package yichang;
import java.util.Scanner;
import java.util.Arrays;
public class Library2 {
?public void show() throws CommondException,NotfoundException{
??Scanner input=new Scanner(System.in);
??Book book=new Book(new String[][]{
????{"1","唐詩三百首","T300"},
????{"2","十萬個為什么","S1000"},
????{"3","三體","S3"},??
????{"4","java教程","J100"}});
??System.out.println("******************歡迎來到圖書管理系統!*******************");
??System.out.println("*****輸入命令:1-按照序號查找圖書;2-按照名稱查找圖書*****");
??int i1=input.nextInt();
??if(i1==1) {
???System.out.println("請輸入圖書序號:");
???int i2=input.nextInt();???
???if(i2<1||i2>4) {
????throw new NotfoundException("圖書不存在,請重新輸入!");
???}else {
????System.out.println("序號:"+book.book[i2-1][0]+"\t"+"名稱:"+book.book[i2-1][1]+"\t"+"編碼:"+book.book[i2-1][2]);
???}
??}else if(i1==2){
????System.out.println("請輸入圖書名稱:");
????String name=input.next();
????int a=0;
????for(int i=0;i<3;i++) {
?????if(name.equals(book.book[i][1]) ){
??????System.out.println("序號:"+book.book[i][0]+"\t"+"名稱:"+book.book[i][1]+"\t"+"編碼:"+book.book[i][2]);?
??????a=1;
??????break;
?????}
????}
????if(a==0) {
?????throw new NotfoundException("圖書不存在,請重新輸入!");
????}
??}
?}
??
?
?public static void main(String[] args) {
??// TODO 自動生成的方法存根
??Library2 kk=new Library2();
??try {
??kk.show();
??}catch(NotfoundException e) {
???e.printStackTrace();
??}catch(CommondException e) {
???e.printStackTrace();
??}
?}
?
}
2017-08-31
如代碼 第一次運行的時候用名稱查找圖書沒什么問題 第二次再運行之后就會開始拋出找不到圖書錯誤 請問是哪里出了問題?