I have the following method and I wanted to change the for each loops to normal for loops. So I tried something like this
for (int i = 0; i < above.length(); i++) {
    char x = above.toCharArray();
    if (x == 'x') {
        counter++;
    }
}
But I know that's wrong. So, what's the right way to change these for each loops to normal for loops?
public static int neighbourconditions(String above, String same, String below){
    int counter = 0;
    if(above != null){
        for(char x : above.toCharArray()){
            if(x == 'x'){
                counter++;
            }
        }
    }
    for (char x : same.toCharArray()){
        if (x == 'x'){
            counter++;
        }
    }
    if (below != null){
        for(char x : below.toCharArray()){
            if (x == 'x'){
                counter++;
            }
        }
    }
    return counter;
}
 
     
     
     
    