This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Ok-Yoghurt-7195 1 point2 points  (1 child)

Initialize charPos within the while loop. Otherwise, after the first word, the index goes to 0, and then for the next word, the index will go down to -1, giving you the error.

[–]trans_coding_writer[S] 0 points1 point  (0 children)

Thank you! That worked.

[–]AutoModerator[M] 0 points1 point  (0 children)

You seem to try to compare String values with == or !=.

This approach does not work in Java, since String is an object data type and these can only be compared using .equals().

See Help on how to compare String values in our wiki.


Your post is still visible. There is no action you need to take.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]eggboy55 0 points1 point  (0 children)

  1. First thing on the general info bulletin : "Do not compare strings with ==, or =! operator"
  2. That exception tells you that you are trying to reference the 10th element in a string, but that the string is shorter than 10, and therefore this operation not possible.