package com.itheima;
import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.print("请输入方阵的阶数:");
int n=in.nextInt();
showResult(n);
}
public static int findMin(int a,int b,int c,int d){
return Math.min(Math.min(a,b),Math.min(c,d));
}
public static void showResult(int n){
for (int i = 1; i < n+1; i++) {
for (int j = 1; j < n+1; j++) {
System.out.print(findMin(i, j, Math.abs(n-i)+1, Math.abs(n-j)+1));
System.out.print(" ");
}
System.out.println();
}
}
} |