【发布时间】:2015-04-24 06:52:46
【问题描述】:
通常,我没有问题扫描数组列表中的某些元素。我知道如何构建 while 循环等。但是,在这种情况下,我需要使用扫描仪,但它给出了我的问题,如下所示:
以下代码旨在使用扫描仪输入作者和书名,以检查该书(由作者和书名的精确匹配组成)是否在数组列表中。
很可能我忽略了一些简单的事情,但无论如何,我不需要任何 cmets 评论这是一个愚蠢的代码等。
public String checkForBookUsingInfo(){
int index = 0;
Book bookObject = null;
String returnValue = "Book not found";
String title = "";
String author = "";
Boolean isFound = false;
while (index <bookList.size() && isFound == false ){
bookObject = bookList.get(index);
System.out.println("Please enter title of book to search for.");
String anyTitle = keybd.next();
System.out.println("Please enter author of book to search for.");
String anyAuthor = keybd.next();
if ((title.equals(anyTitle)) && (author.equals(anyAuthor))){
returnValue = "Book is in library.";
}
index++;
}
return returnValue;
【问题讨论】:
标签: java arraylist java.util.scanner bluej