![]()
1 package com.workprojects;
2 /**
3 * 使用双重循环,根据用户输入的数字,输出三角形状逐渐加大
4 * 2019-07-02
5 * @author L
6 */
7 import java.util.Scanner;
8
9 public class Work070205 {
10 static Scanner sc =new Scanner(System.in);
11 public static void main(String[] args) {
12 System.out.print("请想要几行数字?");//需求行数为1-9行,超过两位数会出现变形
13 int num = sc.nextInt();//输入需求行数
14 for(int i =1 ; i<=num;i++) {//行数,总行数小于等于需求行数
15 for(int a=0;a<num-i;a++) {//每行前空格数,空格需求为需求行数-当前行数
16 System.out.print(" ");
17 }
18 for(int j=1;j<=2*i-1;j++) {//每行的列数,根据规律得出2*-1
19 System.out.print(i);
20 }
21 System.out.println();
22 }
23 }
24 }