/**
* 实心菱形
*/
public static void method8() {
System.out.print("请输入实心菱形的行数:");
int n = in.nextInt();
int upRows = n / 2, starControl = 2, spaceControl = -1, spaceNum = n / 2, starNum = 1;
for (int i = 0; i < n; i++) {
if (i >= upRows) {
starControl = -2;
spaceControl = 1;
}
for (int j = 0; j <= spaceNum; j++) {
System.out.print(" ");
}
spaceNum += spaceControl;
for (int j = 0; j < starNum; j++) {
System.out.print("*");
}
starNum += starControl;
System.out.println();
}
}
/**
* 空心菱形
*/
public static void method9() {
System.out.print("请输入空心菱形的行数:");
int n = in.nextInt();
int upRows = n / 2, spaceContentControl = 2, spaceContentNum = 1, spaceControl = -1, spaceNum = n / 2;
for (int i = 0; i < n; i++) {
if (i >= upRows) {
spaceControl = 1;
spaceContentControl = -2;
}
for (int j = 0; j <= spaceNum; j++) {
System.out.print(" ");
}
spaceNum += spaceControl;
if (i > 0 && i < n - 1) {
System.out.print("*");
for (int j = 0; j < spaceContentNum; j++) {
System.out.print(" ");
}
spaceContentNum += spaceContentControl;
System.out.print("*");
* 空心菱形
*/
public static void method9() {
System.out.print("请输入空心菱形的行数:");
int n = in.nextInt();
int upRows = n / 2, spaceContentControl = 2, spaceContentNum = 1, spaceControl = -1, spaceNum = n / 2;
for (int i = 0; i < n; i++) {
if (i >= upRows) {
spaceControl = 1;
spaceContentControl = -2;
}
for (int j = 0; j <= spaceNum; j++) {
System.out.print(" ");
}
spaceNum += spaceControl;
if (i > 0 && i < n - 1) {
System.out.print("*");
for (int j = 0; j < spaceContentNum; j++) {
System.out.print(" ");
}
spaceContentNum += spaceContentControl;
System.out.print("*");
} else {
System.out.print("*");
}
System.out.println();
}
}
System.out.print("*");
}
System.out.println();
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/f96cea755335856d2d2e1e639d7bb65f.png)