- 2
Explain the output:- java.lang.StringIndexOutOfBoundsException: String index out of range: 3
The numerical value 3 is same in the inputs "Can you not do that?" and "The longest word in the dictionary is..." and others are hidden. The question I was solving is Average Word Length in the code coach level medium.
2 Réponses
+ 1
Generally speaking, String in Java is an array of chars. Like in every other array indexes are starting from 0. This exception is thrown when you are trying to access this array by index, which does not exist.
Example:
String s = "Java";
s.charAt(4); will throw this exception.
It is hard to tell more without looking at your code.
0
Aleksandrs Kalinins here is my code:
https://code.sololearn.com/cR6GAeQK103B/?ref=app