TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|

- import java.util.Scanner;
-
- public class Christ {
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Christ temp = new Christ();
- System.out.println("请输入您需要的圣诞树的大小
-
- ");
- Scanner input = new Scanner(System.in);
- int a = input.nextInt();
- temp.ChristmasTree(2*a);
- }
-
-
- void ChristmasTree(int n) {
- int i, j, k, m;
- for (i = 1; i <= n / 2; i++) {
- for (j = 1; j < n / 2 + i; j++) {
- if (j <= n / 2 - i)
- System.out.print(" ");
- else {
- if (j % 2 == 0)
- System.out.print("*");
- else
- System.out.print("$");
- }
- }
- System.out.print("
- ");
- }
- for (k = n / 2 + 1; k <= n - n / 4; k++) {
- for (m = 1; m <= n + 1; m++) {
- if (m != n / 2)
- System.out.print(" ");
- else
- System.out.print("||");
- }
- System.out.print("
- ");
- }
-
- }
-
- }
-
复制代码 |
|