I am trying to understand the error message I am getting with this code. I wrote this program for the sole purpose of changing the index value from the tutorial in the book I am working through. In the line assigning a value to 'c2', when I leave the index value at 0 it works fine and grabs the next value from the string 'test' I am entering. If I change the value to a 1 or 2, it throws the below error message. Can anyone let me know why my code is throwing this error as from my understanding thus far, 1 is within range of the string I am using? I have checked some java documentation but the most I've gotten from it is the error is caused by me trying to access a value outside the index range. Maybe I'm using either charAt() or findWithinHorizon() wrong?
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(Unknown Source)
Thank you in advance!
The two people in this world are those that do, and those that don't.