1 package learning; 2 3 import java.util.Scanner; 4 5 public class t2{ 6 public static void main(String[] args){ 7 Scanner s=new Scanner(System.in); 8 int n=s.nextInt(); 9 for(int i=1;i<=n;i++){ 10 for(int j=n-i;j>0;j--){ 11 System.out.print(" "); 12 } 13 for(int k=1;k<=2*i-1;k++){ 14 System.out.print("*"); 15 } 16 System.out.println(); 17 18 } 19 } 20 }
输出结果: