public class Diamond { public static void main(String[] args) { printSelf(7); } public static void printSelf(int arg) { final int LINE = arg; final int HALF = LINE/2; for(int i=0; i<LINE*LINE; i++) { int row = i/LINE;//表示的是元素所在的行号 int col = i%LINE;//表示的是每行元素的编号从0开始到6结束 //换行的条件 if(i > 0 && col == 0) { System.out.println(); } System.out.print(Math.abs(HALF - col) + Math.abs(HALF - row) > HALF ? ' ' : '*'); } } }
posted on 2010-10-10 18:24 freehell 阅读(223) 评论(0) 收藏 举报
博客园 © 2004-2025 浙公网安备 33010602011771号 浙ICP备2021040463号-3