Java - 2D array checking diagonal number board
<p>Currently I'm working on a program that generates random 0's and 1's in a 8x8 2D array board. What I have to do is check whether or not if all the numbers on the diagonal are the same (starting from the corners, not just any diagonals).</p>
<p>example:</p>
<pre><code>int[][] array = {
    {0, 0, 0, 0, 0, 0, 0, 1},
    {0, 0, 1, 0, 1, 0, 1, 0},
    {0, 0, 0, 0, 1, 1, 1, 0},
    {0, 0, 0, 0, 1, 1, 1, 0},
    {0, 0, 1, 1, 0, 1, 1, 0},
    {0, 0, 1, 0, 0, 0, 1, 0},
    {0, 1, 0, 0, 0, 0, 0, 0},
    {1, 0, 0, 1, 1, 1, 1, 0}
};
</code></pre>
<p>So if by chance all the numbers starting from the top left corner (0,0),(1,1)...(7,7) are all either 0's or 1's then I have to output to the scanner indicating that &quot;There is a major diagonal of 0&quot; (from the example above).</p>
<p>Also from this example, we can see that from the top-right, the number &quot;1&quot; is repeated diagonally towards the bottom left, then I also have to display &quot;There is a minor diagonal of 1&quot;.</p>
<p>So far I have figured out how to generate and input the numbers into the array, but I don't know how to check. This is what I have so far:</p>
<pre><code>public class JavaTest{
// Main method
public static void main(String[] args) {

    int[][] array = {
        {0, 0, 0, 0, 0, 0, 0, 1},
        {0, 0, 1, 0, 1, 0, 1, 0},
        {0, 0, 0, 0, 1, 1, 1, 0},
        {0, 0, 0, 0, 1, 1, 1, 0},
        {0, 0, 1, 1, 0, 1, 1, 0},
        {0, 0, 1, 0, 0, 0, 1, 0},
        {0, 1, 0, 0, 0, 0, 0, 0},
        {1, 0, 0, 1, 1, 1, 1, 0}
    };

    // Print array numbers
    for (int i = 0; i &lt; array.length; i++) {
        for (int j = 0; j &lt; array[i].length; j++)
            System.out.print(array[i][j] + &quot; &quot;);
        System.out.println();
    }
    // Print checkers

    checkMajorDiagonal(array);
}
// Check major diagonal 
public static void checkMajorDiagonal(int array[][]) {
    int majDiag;
    boolean isMatching = true;
    int row = 0;
    for(row = 0; row &lt; array.length; row++){
        majDiag = row;
        if(array[row][row] != array[row+1][row+1]){
            isMatching = false;
            break;
        }
    }
    //If all elements matched print output
    if(isMatching)  
        System.out.println(&quot;Major diagonal is all &quot; + array[row][row]);
    }
}
</code></pre>
<p>Though what I have so far is not working as I want it to be as there is an error, and I still have to do the minor diagonal. Thanks in advance.</p>