I am trying this "Be the compiler" example from Head First Java, Chapter 3. The below is the code and output. I have multiple questions on this:
1. I did not understand the flow (Sorry I am new bee)
2. I am getting Array Out of Bounds Exception, what is causing for this and how would I rectify it?
3. Why the 'Z' was incremented right after the condition in while loop?
Precisely, I am asking you to help me understand this program. Appreciate for your time!
I moved the Z increment as the last statment. However I still get this Array Out of Bounds Exception. The below is the output:
bilbo is a good Hobbit name
frodo is a good Hobbit name
Sam is a good Hobbit name
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
Joined: Nov 04, 2010
I changed the condition to be Z<3 which solved the purpose. Since there are only three elements in array making it less than 3 would suffice. Thank you very much!