Search in a 2D array to find if there is a row or a column that contains the word “error” in every cell of that row or column Search in a 2D array to check if there is a column or a row in the 2D Array thats contains all the word “error”, if yes return the index of that row or column else return 0;
Exception: if the row index equals the column index then it does not matter if contains the word &quot;error&quot; or not. FYI, n is the size of 2D array (number of rows = number of columns)

I wrote this code and I want to check with you if you agree with the logic:
int search(int n, String[][] myArray) {
        int j, k;
        boolean isError;

        //To search per ROW
        for (int i = 1; i &lt;= n; i++) {
            j = 1;
            isError = true;

            while (j &lt;= n &amp;&amp; isError) {
                if ((i != j) &amp;&amp; (myArray[i][j] != &quot;error&quot;)) {
                    isError = false;
                }

                if (j == n &amp;&amp; isError) {
                    return i;
                } else {
                    j++;
                }
            }
        }//end for loop

        //To search per COLUMN
        for (int i = 1; i &lt;= n; i++) {
            k = 1;
            isError = true;

            while (k &lt;= n &amp;&amp; isError) {
                if ((i != k) &amp;&amp; (myArray[k][i] != &quot;error&quot;)) {
                    isError = false;
                }

                if (k == n &amp;&amp; isError) {
                    return i;
                } else {
                    k++;
                }
            }
        }//end for loop

        return 0;

    }
My Java is a bit rusty but I'm not seeing any logical issues with the code doing what you want it to.

Since you return just the row or column index, the caller can't tell from that if the match was a row or a column.