import java.util.Scanner;
public class TwoArray_03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入~");
int n = sc.nextInt();
if(n%2==0){
System.out.println("请输入奇数");
return;
}
int array[][] = new int[n][n];
int a = n-1;
int b = n/2;
for(int i=1;i<=n*n;i++){
array[a++][b++]=i;
if(i%n==0){
a=a-2;
b=b-1;
}else{
a=a%n;
b=b%n;
}
}
System.out.println(n+"阶幻方如下:");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(" "+array[i][j]);
}
System.out.println();
}
}
}
相关分类