user12845610
user12845610

Reputation:

unable to check all elements in array

private void clear() {
    for (int i = 0; i<9; i++){
        for (int j = 0; j<9; j++){
            if(iseditable(i,j)){
                bord[i][j].setText("");
            }
        }
    }
}

private boolean iseditable(int i, int j) {
    for (String s : generatedXY) {
        char[] m = s.toCharArray();
        char x = (char) (i + '0');
        char y = (char) (j + '0');
        return m[1] != x || m[3] != y;
    }
    return false;
}

I have used the following code in my app here generatedXY array contains all the points in the formate (i,j) as strings I want to extract i & j from the string and compare them with index of board but it is only checking the first element of generatedXY it is not all elements

Upvotes: 0

Views: 51

Answers (1)

Stefan
Stefan

Reputation: 1803

First your for loops go from 0 to 8, I assume you wanted to write i<=9 instead.

Second: For iterate over all elements of generatedXY, but you exit loop already in the first iteration by the return statement. You possibly wanted to write something like

if (m[1] != x || m[3] != y) 
{ 
    return true; 
}

, then the return statement is only executed if the condition is true.

Upvotes: 1

Related Questions