0
Nested for loop Problem
public class Loopa{ public static void main(String[] args){ char[] trouble = {'t', 'r', 'o', 'b', 'l', 'e'}; char[] bubble = {'b', 'u', 'b', 'b', 't', 'e'}; int numberOfSameCharacters = 0; for(int i = 0; i < trouble.length; i++){ for(int j = 0; j < bubble.length; i++){ if(trouble[i] == bubble[j]){ numberOfSameCharacters++; } } } } } It's giving me this error Exception in thread "main" java.lang.ArrayIndexOutBoundsException: Index 6 out of bounds for length 6 at Loopa.main(Loopa.java:11)
2 Antworten
+ 2
I think your second loop should be like this
for (int j = 0; j < bubble.length; j++)
You wrote i++ as the increment instead of j++
+ 1
Can't believe i made this mistake
thank you @Agent_l