//不用二维数组实行回行数 真香
public class Test { public static void main(String[] args) { int n = 10; //回行树阶数 for (int i = 0; i < n*n; i++) { System.out.print(String.format("%3d", resolve(n, i+1))+","); if((i+1)%n == 0){ System.out.println(); } } System.out.println(); } public static int resolve(int n, int x){ if(x < n){ return x; } if(x%n == 0){ return x/n + n - 1; } if((n-1)*n < x && n*n>=x){ return n*(n+2)-1-x; } if(x%n == 1){ return 4*n-x/n-3; } return 4*(n-1) + resolve(n-2, x-x/n*2-n+1); } }