求大牛解答,哭哭哭哭,写了一堆老是卡在
package search.Sequence; public class BookIndex { private String BookName; private int BookNumber; public void setBookName(String BookName){ this.BookName = BookName; } public void setBookNumber(int BookNumber){ this.BookNumber = BookNumber; } public String getBookName(String testBookName){ testBookName = this.BookName; return testBookName; } public int getBookNumber(){ return this.BookNumber; } public BookIndex(String newBookName,int newBookNumber){ this.setBookName(newBookName); this.setBookNumber(newBookNumber); } }
package search.Sequence; import java.util.Scanner; public class Searching { public static void main(String[] args) { // TODO 自动生成的方法存根 BookIndex [] PutIndex={new BookIndex("达芬奇密码",1), new BookIndex("计算",2), new BookIndex("数据分析",3), new BookIndex("唐家三少吃屎",4), new BookIndex("天蚕土豆吃屎",5), new BookIndex("卫斯理",6), new BookIndex("侦探伽利略",7), new BookIndex("达文西打字法",8), new BookIndex("东京食屎狗",9)}; int esp ; do{ esp = 0; System.out.println("输入【1】按照编号查询书籍,【2】按照书名查询书籍:"); Scanner InPut_1 = new Scanner(System.in); int putnum = InPut_1.nextInt(); if(putnum == 1){ System.out.println("输入您想找的书籍编号:"); int putBookNumber = InPut_1.nextInt(); for(int i=0;i<i+1;i++){ int a=PutIndex[i].getBookNumber(); if(a==putBookNumber){ String outName = null; System.out.println("书籍是:"+PutIndex[i].getBookName(outName)); break; }else{continue;} } } else if(putnum == 2){ System.out.println("输入您想找的书籍名字:"); String putBookName = InPut_1.nextLine(); for(int i=0;i<i+1;i++){ String testBookName = null; PutIndex[i].getBookName(testBookName);/*这里老是出问题,之前是无参的不能赋值给别的变量,想不到我现在有参了还是这样子,出错*/ if(putBookName==testBookName){ System.out.println("书籍是:"+PutIndex[i].getBookName(testBookName)); break; }else{continue;} } } else{esp=1; System.out.println("输入有误请重新输入"); } }while(esp == 1); } }
求大牛解答我的问题,我先不考虑写try……catch的类,我要先解决图书的问题,想了我一整天了