public class Rhombus { public static void main(String[] args) { printRhombus(15); } /** * 用 * 号打印层数为 n 的菱形 * @param lineNum 菱形层数 */ public static void printRhombus(int lineNum) { int asteriskNum = 1; for (int l = 1;l <= lineNum;l++) { int a = asteriskNum; int b = (lineNum - asteriskNum) / 2; while (b > 0 | a > 0) { if (b > 0) { System.out.print(" "); b--; } else { System.out.print("*"); a--; } } System.out.print(' '); if (l + 1 <= (lineNum / 2) + 1) { asteriskNum = asteriskNum + 2; } else { asteriskNum = asteriskNum - 2; } } } }