【发布时间】:2019-02-04 22:43:39
【问题描述】:
我需要使用 main 方法 中的 array 并将其转移 到我的 getBook 方法 和然后将一个新创建的对象返回给 main 方法中的数组。
我决定将数组转移到下一个方法,方法与扫描仪相同,直到我需要在出错时调用该方法。
public class BookShopApplication
{
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, Book books[])
}
}
public static Book[] getBook(Scanner kybd, Book books[])
{
System.out.println("What is the title of the next book?");
String readTitle = kybd.nextLine();
System.out.println("What is thr title of thje next book?");
String readAuthor = kybd.nextLine();
if (readAuthor == null)
{
for (int i = 0; i < books.length; i++)
{
books[i] = new Book();
books[i].Book(readTitle);
}
}
else
{
for (int i = 0; i < books.length; i++)
{
books[i] = new Book();
books[i].Book(readAuthor, readTitle);
}
}
return books;
}
}
我需要的结果是将书籍返回到数组并存储。
【问题讨论】:
-
你的错误是什么?
-
@Jaquarh 第 14 行不是声明
-
public static Book[] getBook(Scanner kybd, Book[] books)- books 是变量,Book[]是数据类型。在调用该方法后,您还缺少;- 您有语法错误