-
Notifications
You must be signed in to change notification settings - Fork 0
/
holidayTree.java
67 lines (63 loc) · 1.73 KB
/
holidayTree.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
public class holidayTree {
public holidayTree(int i) {
if (i == 1) {
q1();
} else {
q2();
}
}
public void q1() {
for (int i = 0; i < 6; i++) {
for (int k = 0; k < 6 - i; k++) {
System.out.print(" ");
}
for (int j = 0; j < i * 2 + 1; j++) {
System.out.print("*");
}
System.out.print("");
}
for (int i = 0; i < 1; i++) {
for (int x = 0; x < 6; x++) {
for (int k = 0; k < 6 - x; k++) {
System.out.print(" ");
}
for (int j = 0; j < x * 2 + 1; j++) {
System.out.print("*");
}
System.out.print("");
}
}
for (int k = 0; k <= 4; k++)
System.out.println(" **");
}
public void q2() {
int height = 10;
int width = 2 * height - 1;
int star = 1;
int space = width / 2;
for (int i = 0; i < height; i++) {
for (int j = 0; j < space; j++) {
System.out.print(" ");
}
for (int j = 0; j < star; j++) {
System.out.print("*");
}
System.out.println();
star += 2;
space--;
}
for (int i = 0; i < 6; i++) {
for (int j = 0; j < width / 2; j++) {
System.out.print(" ");
}
for (int j = 0; j < 2; j++) {
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
new holidayTree(1);
new holidayTree(2);
}
}