*
***
*****
*******
*********
***********
*********
*******
*****
***
*
package study;
public class LingXing {
public static void main(String[] args) {
printLingXing(11);
}
static void printLingXing(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++)
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++)
System.out.print('*');
System.out.println();
}
}
}
|
|