package com.lzk.test;
import java.util.Scanner;
public class test {
// *
// ***
// *****
// *******
// *********
//空格 * 空格
//4 1 4
//3 3 3
//2 5 2
//1 7 1
//0 9 0
public static void main(String[] args) {
//输入打印几行
Scanner sc = new Scanner(System.in);
System.out.println("请输入打印几行星星:");
int n = sc.nextInt();
printStars(n);
}
public static void printStars(int n) {
//打印n行
for (int i = 1; i <= n; i++) {
//打印空格
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
//打印星号
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");
}
//打印空格
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
System.out.println();
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.