我遇到了返回已創建的對象書的問題,任何幫助將非常感激。該程序要求一本書,然後是作者,並將其存儲在一個對象(書)中。然後它被保存到一系列書籍中。Java |找不到符號|返回對象
**import java.util.*;
public class BookShop {
public static void main(String[] args) {
Scanner kybd = new Scanner(System.in);
book[] books = new book[10];
for (int i = 0; i < books.length; i++){
books[i] = getBook(kybd);
}
printBookDetails(books);
}
private static book getBook(Scanner kybd) {
System.out.print("What Is The Title Of The Next Book?:> ");
String title = kybd.nextLine();
System.out.print("Who Is The Author Of The Next Book?:> ");
String author = kybd.nextLine();
if(author == null){
book definedBook = new book();
definedBook.setTitle(title);
}
else{
book definedBook = new book();
definedBook.setTitle(title);
definedBook.setAuthor(author);
}
return definedBook;
}
private static void printBookDetails(book[] books) {
}
}**
哪裏是書的重要嗎?它在同一個包裏嗎? – 2015-02-23 05:16:03
移動book definedBook = new book();到if ... else語句的外部。 – 2015-02-23 05:17:08
你在哪裏有問題?你是否得到例外? – jmcg 2015-02-23 05:18:01