一、代码(Java实现)
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.println(\"请输入星形行数(奇数):\");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt()/2+1;
for (int i = 0; i < n - 1; i++) {
for (int x = i + 1; x < n; x++) {
System.out.print(\" \");
}
for (int y = 0; y < (i + 1) * 2 - 1; y++) {
System.out.print(\"*\");
}
System.out.println();
}
for (int i = 0; i < n; i++) {
for (int x = 0; x < i; x++) {
System.out.print(\" \");
}
for (int y = i; y < 2 * n - i - 1; y++) {
System.out.print(\"*\");
}
System.out.println();
}
}
}
二、输出结果
因篇幅问题不能全部显示,请点此查看更多更全内容