0

the output is supposed to be like this:
1 0 0 1
0 1 1 0
0 1 1 0
1 0 0 1

what I have is this:
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

import java.util.*;

class Array{

        public static void main(String args[]){

                int[][] M;
                M = new int[4][4];

                for(int row=0; row<4; row++){
                        for(int col=0; col<4; col++){
                                if(row==col)
                                        M[row][col] = 1;
                                else
                                        M[row][col] = 0;
                        }
                }

                for(int row=0; row<4; row++){
                        System.out.println();
                        for(int col=0; col<4; col++){
                                 System.out.print("  "+M[row][col]);
                        }
                }
        }
}

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by nard23
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.