int q = 9;
for (int i = 1; i < 9; i += 2) {
q--;
for (int j = q; j >= 1; j--) {
System.out.print(" ");
}
for (int n = 1; n <= i; n++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 5; i >= 1; i -= 2) {
q++;
for (int j = q; j >= 1; j--) {
System.out.print(" ");
}
for (int u = 1; u <= i; u++) {
System.out.print("*");
}
System.out.println();
}
效果图如下:
![](https://i-blog.csdnimg.cn/blog_migrate/788139ee2289d1a3dc8053a2bab2f01c.png)