打印数字三角形 - 两个正方形

Printing number triangle - squares of two

         1
       2 1 2 
     4 2 1 2 4 
   8 4 2 1 2 4 8

尝试打印上面的三角形,但我很难打印两个 (n *= 2) 的正方形。我该如何合并这个?目前,它给了我以下输出。感谢你的帮助。 当前输出(数字不正确):

         1
       2 1 2 
     3 2 1 2 3 
   4 3 2 1 2 3 4

到目前为止,这是我的代码(例如,高度 = 4):

     for(int i=1; i<=height; i++) {

        for (int j = 1; j <= height-i; j++) 
            System.out.print("   ");

        for(int k=i; k>=2; k--) 
            System.out.printf("%-3d",k);

        for(int l=1; l<=i; l++) 
            System.out.printf("%-3d",l);

    System.out.println();
    }

好了

     for(int i=1; i<=height; i++) {
        for (int j = 1; j <= height-i; j++) 
          System.out.print("   ");

        for(int k=1<<i-1; k>=2; k>>=1) 
          System.out.printf("%-3d",k);

        for(int l=1; l<=1<<i-1; l<<=1) 
          System.out.printf("%-3d",l);

        System.out.println();
     }

code.