static void printVacantLingXing(int n) {
// 打印上半部分
for (int h = 1; h <= (n + 1) / 2; h++) {
for (int l = 1; l <= (n + 1) / 2 - h; l++)
// 每行‘*’前的空格
System.out.print(' ');
for (int num = 1; num <= 2 * h - 1; num++)
if (num == 1 || num == 2 * h - 1)
System.out.print('*');
else
System.out.print(' ');
System.out.println();
}
// 打印下半部分
for (int h = 1; h <= n / 2; h++) {
for (int l = 1; l <= h; l++)
System.out.print(' ');
for (int num = 1; num <= 2 * ((n + 1) / 2 - h) - 1; num++)
if (num == 1 || num == 2 * ((n + 1) / 2 - h) - 1)
System.out.print('*');
else
System.out.print(' ');
System.out.println();
}
}
|
|