+ 3

# Why index out of bounds?

I need to do the nested for loop on my code below, but whatever I do to that loop, like doing the usual array.length - 1, it says that the index is out of bounds. I can usually fix the problem, but on this case, I need help. I never tried that code on IntelliJ IDEA on my old PC. How can I rectify this problem? https://code.sololearn.com/cb4q1tVVapae/?ref=app

15th Feb 2019, 8:18 PM
EoflaOE
+ 3
One way to solve it could be conceptually that you change your stillvowel variable to int instead of boolean, and make it a counter. If you allow only one shift then inside the nested loop check also the value of the counter and the value of the boolean parameter.
15th Feb 2019, 9:11 PM
Tibor Santa
+ 5
You may surround your code with try catch try{ } catch (ArrayIndexOutOfBoundsException e){ }
16th Feb 2019, 4:21 AM
Muhd Khairul Amirin
+ 4
Well done ;)
16th Feb 2019, 1:17 PM
Tibor Santa
+ 3
Its easy. You were incrementing the wrong variable in your nested loop. Should be: for (int j=0;j<vow.length;j++){
15th Feb 2019, 8:27 PM
Tibor Santa
+ 2
Based on your test case, a and 4, the function is never actually called recursively. Thats why your third boolean parameter does not seem to be working. first the letter a is shifted to e inside the nested loop. Then in the following cycles of j, the letter e is compared again to all other vowels and replaced again when the loop hits e, and then again when it hits i.
15th Feb 2019, 9:05 PM
Tibor Santa
+ 1
Thank you! I did not see the j and i as I am feeling asleep. Now, just one thing. The first call acts like I have novowels set to true when calling, leading to the output that I don't want. For example: Input: a 4 Output: Original string: a Modified 1 time: m (Should be e) Modified string: m (correct)
15th Feb 2019, 8:46 PM
EoflaOE
+ 1