1 2 1
输出: 1 121 12321 1234321
class PrintOneRow { private int length; public PrintOneRow(int length) { this.length = length; } public void printRow() { for (int i = 0; i <= length/2; i++) { System.out.print(i+1); } for (int j = 0; j < length/2; j++) { System.out.print(length / 2 - j); } System.out.println(); } } class PrintNum { public static void main(String[] args) { int numOfRows = 4; PrintOneRow printOneRow; for (int i = 1; i <= numOfRows; i++) { for (int j = 0; j < numOfRows - i; j++) { System.out.print(" "); } new PrintOneRow(2 * i - 1).printRow(); } } }