class Books
{
String title;
String author;
}
class BooksTestDrive
{
public static void main (String args[])
{
Books[] myBooks = new Books[3];
myBooks[0] = new Books(); // cria objetos Books
myBooks[1] = new Books();
myBooks[2] = new Books();
myBooks[0].title = "as";
myBooks[1].title = "df";
myBooks[2].title = "gh";
myBooks[0].author = "bob";
myBooks[1].author = "sue";
myBooks[2].author = "ian";
int x = 0;
while (x < 3)
{
System.out.println(myBooks[x].title);
System.out.println(" by ");
System.out.println(myBooks[x].author);
x = x + 1;
}
}
}
class TestArrays
{
public static void main (String args[])
{
int[] index = new int[4];
index[0] = 1;
index[1] = 3;
index[2] = 0;
index[3] = 2;
String[] islands = new String[4];
islands[0] = "Bermuda";
islands[1] = "Fiji";
islands[2] = "Azores";
islands[3] = "Cozumel";
int y = 0;
int ref;
while (y < 4)
{
ref = index[y];
System.out.println("Island = ");
System.out.println(islands[ref]);
y = y + 1;
}
}
}
Porque no primeiro código o livro pede pra criar os objetos Books e no segundo código não pede pra criar os objetos islands??