fork(3) 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. for(int i = 0; i < n; i++) {
  21. for(int y = 0; y < n; y++) {
  22. if(m[i][y] != 1) {
  23. m[i][y] = 0;
  24. }
  25. }
  26. }
  27. for(int i = 0; i < n; i++) {
  28. for(int y = 0; y < n; y++) {
  29. System.out.println(m[i][y] + " ");
  30. }
  31. System.out.println("\n");
  32. }
  33. }
  34. }
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