1 package debug; 2 3 public class Demo10 { 4 public static void main(String[] args) { 5 //用星星符號打印出一個直角三角形 6 for(int i=1;i<=5;i++) { 7 //每一列打印的星星個數跟行數相同 ,所以在下面for循環中將條件中最大值設置為行數 8 for(int j=1;j<=i;j++) { 9 System.out.print("*"); 10 } 11 System.out.println(); 12 } 13 } 14 15 }
輸出如下:
* ** *** **** *****