简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM