fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int n;
  13. Scanner scanIn = new Scanner(System.in);
  14.  
  15. n = scanIn.nextInt();
  16. int[][] m = new int[n][n];
  17. for(int i = 0; i < n; i++) {
  18. m[i][i] = 1;
  19. }
  20.  
  21. for(int i = 0; i < n; i++) {
  22. for(int y = 0; y < n; y++) {
  23. System.out.println(m[i][y] + " ");
  24. }
  25. System.out.println("\n");
  26. }
  27. }
  28. }
Success #stdin #stdout 0.09s 2841600KB
stdin
4
stdout
1 
0 
0 
0 


0 
1 
0 
0 


0 
0 
1 
0 


0 
0 
0 
1