fork download
  1. class ideone
  2. {
  3. public static void main(String args[])
  4. {
  5. int m=3; //the size of matrix
  6.  
  7.  
  8. int a[][]=new int[m*m][m*m];
  9. int i,j;
  10. i=j=0;
  11.  
  12. while(i<m*m) {
  13. a[i][j]=1;
  14. j+=m;
  15. if(j>=m*m) j=j%(m*m)+1;
  16. i++;
  17. }
  18.  
  19. for(i=0; i<m*m; i++) {
  20. for(j=0; j<m*m; j++) {
  21. System.out.print(a[i][j] + " ");
  22. }
  23. System.out.println();
  24. }
  25.  
  26. }
  27. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
1 0 0 0 0 0 0 0 0 
0 0 0 1 0 0 0 0 0 
0 0 0 0 0 0 1 0 0 
0 1 0 0 0 0 0 0 0 
0 0 0 0 1 0 0 0 0 
0 0 0 0 0 0 0 1 0 
0 0 1 0 0 0 0 0 0 
0 0 0 0 0 1 0 0 0 
0 0 0 0 0 0 0 0 1