java打印圣诞树的算法

300 2024-03-09 14:55

java public class ChristmasTreePrinter { public static void main(String[] args) { int levels = 5; for (int i = 0; i < levels; i++) { for (int j = levels - i; j > 0; j--) { System.out.print(" "); } for (int k = 0; k < 2 * i + 1; k++) { System.out.print("*"); } System.out.println(); } for (int i = 0; i < levels - 1; i++) { System.out.print(" "); } System.out.println("*"); } }
顶一下
(0)
0%
踩一下
(0)
0%
相关评论
我要评论
点击我更换图片