java圣诞节圣诞树
时间: 2023-12-13 18:34:09 浏览: 101
以下是Java实现简单圣诞树的示例代码:
```java
public class ChristmasTree {
public static void main(String[] args) {
int n = 10;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= n - 2; j++) {
System.out.print(" ");
}
System.out.println("***");
}
}
}
```
运行结果:
```
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
***
***
***
```
阅读全文