笨办法了,找规律
public class Test {
public static void main(String args[]) {
int n = Integer.parseInt(args[0]);
int[][] array = new int[2 * n + 1][2 * n + 1];
int a = array[n][n] = n + 1;
for (int i = n - 1; i >= 0; i--) {
for (int j = n; j <= n; j++) {
if (a - 1 >= 1) {
array[j] = a = a - 1;
}
if (a - 1 <= 0) {
array[j] = 1;
}
}
}
for (int i = n; i >= 0; i--) { // 第几行
for (int j = n - 1; j >= 0; j--) { // 第几列
if (array[j + 1] - 1 >= 1) {
array[j] = array[j + 1] - 1;
}
if (array[j + 1] - 1 == 0) {
array[j] = 1;
}
}
}
for (int i = 0; i <= n; i++) {
for (int j = n + 1; j <= 2 * n; j++) {
array[j] = array[2 * n - j];
}
}
for (int i = n + 1; i <= 2 * n; i++) {
for (int j = 0; j <= 2 * n; j++) {
array[j] = array[2 * n - i][j];
}
}
for (int i = 0; i <= 2 * n; i++) {
for (int j = 0; j <= 2 * n; j++) {
System.out.print(array[j] + " ");
}
System.out.println();
}
}
public class Test {
public static void main(String[] args) throws Exception {
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
System.out.println("input ...");
int n = Integer.parseInt(b.readLine());
int[][] a = new int[2* n + 1][2 * n + 1];
//初始化数组
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length; j++) {
a[i][j] = 1;
}
}
//修改数组中的值
for (int i = 0; i <= n; i++) {
int k = i + 1;
for (int j = n; j >= n - i; j--) {
a[i][j] = a[2 * n - i][j] = a[i][2 * n - j] = a[2 * n - i][2 * n - j] = k--;
}
}
//输出数组
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}