1 package com.duan.struct; 2 3 public class TestDemo { 4 public static void main(String[] args) { 5 //打印三角形 5行 6 7 for (int i = 1; i <= 5; i++) { 8 for (int j = 5; j >= i; j--) { 9 System.out.print(" "); 10 } 11 for (int j = 1; j <= i; j++) { 12 System.out.print("*"); 13 } 14 for (int j = 1; j < i; j++) { 15 System.out.print("*"); 16 } 17 18 System.out.println(); 19 } 20 } 21 } 22 23 结果: 24 * 25 *** 26 ***** 27 ******* 28 *********