所以,我有这个小问题。我提示用户输入需要存储在多变量数组中的 3 个变量(Str、Str、Int),但我无法让它工作。任何帮助将不胜感激。
LibraryBook[] book = new LibraryBook[5];
//inputing a new book
Scanner input = new Scanner(System.in);
LibraryBook[] myBook = new LibraryBook[0];
System.out.println("Enter book name: ");
String title = input.nextLine().trim();
System.out.println("Enter author name: ");
String author = input.nextLine().trim();
System.out.println("Enter # pages: ");
int pages = input.nextInt();
myBook[0] =new LibraryBook(title,author,pages);
我收到这个错误
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at LibraryBookSort.main(LibraryBookSort.java:36)
----jGRASP楔2:进程退出代码为1。