ITeye博客

1 2 1

meifage2 · 2011-08-11 14:42 · 诡异面试题 · 企业架构 · Markdown

输出: 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(); } } }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。