+ 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
9 Respostas
+ 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.
+ 5
You may surround your code with try catch
try{
}
catch (ArrayIndexOutOfBoundsException e){
}
+ 4
Well done ;)
+ 3
Its easy. You were incrementing the wrong variable in your nested loop. Should be:
for (int j=0;j<vow.length;j++){
+ 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.
+ 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)
+ 1
Thank you for your answers! I appreciate your help! It now finally works like I need.
0
Thanks!
0
nice