//输入一个数字n(奇数),输出n行菱形
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int down = n/2;//下面down行
int top = n/2+1;//上面有top行
int num1 = top-1;
int num2 = 1;
for(int i = 0;i<top;i++)
{
for (int j = 0; j < num1; j++) {
System.out.print(" ");
}
num1--;
for (int j = 0; j < num2; j++) {
System.out.print("*");
}
num2 += 2;
System.out.println();//换行
}
num1=1;
num2 = down*2-1;
for(int i = 0;i<down;i++)
{
for (int j = 0; j < num1; j++) {
System.out.print(" ");
}
num1++;
for (int j = 0; j <num2 ; j++) {
System.out.print("*");
}
num2 -= 2;
System.out.println();//换行
}
}
02-18
310
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)