本文介绍了这两个方法都与我相同,但只有一个有效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想要打印一系列成员供选择和一系列书籍..我已经多次检查过,但两者看起来完全相同但只有'bookarray'正在打印.. public static Person [] createArray1() { Person [ ] personarray = new Person [5]; personarray [0] =新人(John Smith,67岁,假,1485); personarray [1] =新人(Joe Bailey,58,false,2003); personarray [2] =新人(Barbara Jones,76,false,9191) ; personarray [3] =新人(Felix Anderson,36岁,假,1974年); personarray [4] =新人(Sarah Watson, 27,false,1996); 返回personarray; } public static void printPersons(Person [] personarray) { for(int counter = 0 ; counter> personarray.length; counter ++) { System.out.println(Test2); System.out。 println(counter +。+ personarray [counter] .getString2()); } } public static void choosePerson(选择选择) { Person [] listOfPeople = Service.createArray1(); System.out.println(Test1); Service.printPersons(listOfPeople); } public static Book [] createArray() { Book [] bookarray = new Book [ 3]; //书名,isbn号,onloan = false ..从Book对象传入 bookarray [0] =新书(The Lion,the Witch and the Wardbrobe,80312,false); bookarray [1] =新书(Great Expectations,4232,false); bookarray [2] =新书(指环王,2131,假); 返回bookarray; } public static void printBooks(Book [] bookarray) { for(int counter = 0 ; counter< bookarray.length; counter ++) { System.out.println(counter +。+ bookarray [counter] .getString()); } } public static void orderBooks(Select select) { 预订[] listOfBooks = Service.createArray(); Service.printBooks(listOfBooks); } 我尝试了什么: 测试1在choosePerson正在打印,但printPersons中的测试2没有.. I want to print an array of members to choose from and an array of books.. I have double checked many times, but both seem identical yet only 'bookarray' is printing.. public static Person[] createArray1() { Person[] personarray = new Person [5]; personarray[0] = new Person ("John Smith", 67, false, 1485); personarray[1] = new Person ("Joe Bailey", 58, false, 2003); personarray[2] = new Person ("Barbara Jones", 76, false, 9191); personarray[3] = new Person ("Felix Anderson", 36, false, 1974); personarray[4] = new Person ("Sarah Watson", 27, false, 1996); return personarray; } public static void printPersons (Person[] personarray) { for (int counter = 0; counter > personarray.length; counter++) { System.out.println("Test2"); System.out.println(counter + "." + personarray[counter].getString2()); } } public static void choosePerson(Select select) { Person[] listOfPeople = Service.createArray1(); System.out.println("Test1"); Service.printPersons(listOfPeople); } public static Book[] createArray() { Book[] bookarray = new Book[3]; // book title, isbn number, onloan = false.. passed in from Book object bookarray[0] = new Book ("The Lion, the Witch and the Wardbrobe", 80312, false); bookarray[1] = new Book ("Great Expectations", 4232, false); bookarray[2] = new Book ("The Lord of the Rings", 2131, false); return bookarray; } public static void printBooks(Book[] bookarray) { for (int counter = 0; counter < bookarray.length; counter++) { System.out.println(counter + "." + bookarray[counter].getString()); } } public static void orderBooks(Select select) { Book[] listOfBooks = Service.createArray(); Service.printBooks(listOfBooks); }What I have tried:"Test 1" In choosePerson is printing but "Test 2" in printPersons does not..推荐答案 for循环条件不同 这篇关于这两个方法都与我相同,但只有一个有效。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-18 23:12