共計 233 個字符,預計需要花費 1 分鐘才能閱讀完成。
參考代碼如下:
public class StarTriangle {public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; i++) {for (int j = 1; j <= i; j++) {System.out.print("* ");
}
System.out.println();}
}
}
輸出結果為:
*
* *
* * *
* * * *
* * * * *
你可以根據需要調整 rows
的值來改變輸出的三角形大小。
丸趣 TV 網 – 提供最優質的資源集合!
正文完