- import java.util.Scanner;
- class For_SJX {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入一个行数:");
- int num = sc.nextInt();
- for (int i = 1; i <= num; i++) {
- //控制空格数,规律:每一行的空格数 = 总行数 - 当前行数
- for (int s = 1; s <= num -i; s++) {
- System.out.print(" ");
- }
- //控制每一行的*数,规律:每一行的*数 = 2*当前行数 -1
- for (int x = 1; x <= 2*i -1; x++) {
- System.out.print("*");
- }
- System.out.println();
- }
- }
- }
复制代码
论坛号强大额~~ |
|