Procedural programming veteran, Java OO newbie question, first time poster
The output of this program is:
line 13
line 18
line 20
... and then it hangs. Why does it never get to 23? FYI, this code came from "Head First Java", chapter 3, Code Magnets puzzle (probably not actually intended to run)
Kind of embarrassed that I'm not seeing anything wrong with this simple program...
Thanks,
Kevin
Code Java:
class TestArrays {
public static void main(String [] args) {
int [] index = new int[4];
index[0] = 1; // Figi
index[1] = 3; // Cozumel
index[2] = 0; // Bermuda
index[3] = 2; // Azores
String [] islands = new String[4];
System.out.println("line 13");
islands[0] = "Bermuda"; // 3
islands[1] = "Fiji"; // 1
islands[2] = "Azores"; // 4
islands[3] = "Cozumel"; // 2
System.out.println("line 18");
int y = 0;
System.out.println("line 20");
int ref;
while (y < 4); {
System.out.println("line 23");
ref = index[y];
System.out.print("island = ");
System.out.println(islands[ref]);
y = y + 1;
}
System.out.println("line 30");
}
}
Re: Procedural programming veteran, Java OO newbie question, first time poster
Check your semi-colons on the while loop. You're short-circuiting your loop.
Re: Procedural programming veteran, Java OO newbie question, first time poster
Thanks! I am so not used to ending statements with a semi-colon, and here I did it to excess! You're not really a curmudgeon after all :)
Re: Procedural programming veteran, Java OO newbie question, first time poster