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]);
                        }
                }
        }
}

The "top left to bottom right" is row == col
The "top right" to bottom left" is (row + col + 1) == 4

thanks i appreciate it...works perfect

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.