barry richard wrote:
I am fairly certain that there is no errors in there
I should hope that after seeing the error message, you would be completely certain that there are errors.
Just like in your other thread, the error message is telling you exactly what's wrong.
It's telling you that at line 13 of Example.java, you are trying to access the 6th element (at index 5) of an array that has less than 6 elements (and therefore indices 0..4 at the most).
The vast majority of for-loops you'll write in Java are this one. (In fact I can't remember the last time I wrote a for-loop which did anything but that.)
However you're in school, so I guess you're supposed to learn all of the other possibilities which you might use a for-loop to implement. So go back to your text and read carefully about what the three parts of the for-loop do (the three parts separated by semicolons, that is) and when they do it.
Or if you're more of an experimentalist, try some code:
barry richard wrote:Just some more explanation, I am sure you pros can see it just by looking but What I am trying to do is to read the Array and add a number to each value and then print it
Barry, one thing that may help you parse these exceptions is that they don't lie. Instead of trying to force exceptions to conform to what you believe should be reality, it's better to take the opposite slant. The exceptions and stacktraces are the authorities. What they say is "The Bible" so to speak.
It's very helpful to step through the code as it executes. Most IDEs have excellent debuggers where you can watch values change as each loop rolls by. You will see then exactly where and why it explodes.
Otherwise, I used to insert test code into my code to do System.out.println() as each loop went by. That's another way to see how the progression goes without using a debugger.