0

I'm trying to print the array and I'm receiving an error. The original goal was to create a 10x10, 2 Dimensional array and put the numbers 0 to 9 on the diagonal. I came up with this code but it displays letters instead of numbers:

    int[][] matrix = new int[10][10];

for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
        if(i==j)
            matrix[i][j] = i;
        else matrix[i][j]=0;
        System.out.println(matrix);
    }
}

If anyone can provide any suggestions or push me in the right direction, I would be really thankful. This is only my second question so please forgive any errors as I'm still trying to learn. Thank you

  • `for (int[] mat : matrix) { for (int val : mat) { System.out.print(val + " "); } System.out.println(); }` – DevilsHnd Mar 22 '22 at 23:27

0 Answers0