Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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..
Posted
Updated 11-Jan-18 17:14pm

1 solution

for loop condition is different
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900