Java 代码
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int center = n / 2;
for (int i = 0; i < n; i ++)
{
for (int j = 0; j < n; j ++)
{
if ((Math.abs(i - center) + Math.abs(j - center)) <= n/2)
System.out.print("*");
else
System.out.print(" ");
}
System.out.print("\n");
}
}
}