There is a far more serious mistake, using "< 5" in the for loop. If you pass another
word eg "Goodbye" or "Hiya" you can get errors, either with not printing all the word, or exceptions.
You ought either to use the
for-each loop (enhanced for loop) like this
or use the
length attribute of the arrayBoth those techniques will gaurd against both those problems. In this instance (assuming you are using
Java 5 or 6) the for-each loop is preferable.
And, everybody, please remember the
code button. I have edited one post, so you can see how much better it looks. And always use
ctrl-c ctrl-v to post code with errors in, so we can see the exact mistake.
[ July 24, 2008: Message edited by: Campbell Ritchie ]