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 print (int[][] a)
  11. {
  12. for (int i=0; i<a.length; i++)
  13. {
  14. for (int j=0; j<a[i].length; j++)
  15. System.out.print(a[i][j]+" ");
  16. System.out.println();
  17. }
  18. }
  19. public static int[][] latinsq(int n)
  20. {
  21. int[][] c= new int[n][n];
  22. for (int i=0; i<n; i++)//заполнение массива с заданным свойством
  23. {
  24. int a=i+1;
  25. for (int j=0; j<n; j++)
  26. {
  27. c[i][j]=a;
  28. a++;
  29. if (a>n) a=1;
  30. }
  31. }
  32. return c;
  33. }
  34. public static void main (String[] args) throws java.lang.Exception
  35. {
  36. Scanner in=new Scanner(System.in);
  37. int n;
  38. n=in.nextInt();
  39. print(latinsq(n));
  40. }
  41. }
Success #stdin #stdout 0.13s 321280KB
stdin
4
stdout
1 2 3 4 
2 3 4 1 
3 4 1 2 
4 1 2 3