-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern.java
57 lines (37 loc) · 1.01 KB
/
pattern.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
#Java Implementation to print Christmas tree pyramid pattern
class PrintChristmasTree{
//Value 5 is permanently provided to height variable
public static final int height = 5;
//Main Function
public static void main(String[] args) {
//Assigning Width
int width = 5;
//Assigning Space
int space = width*5;
int x = 1;
//Code to Print Upper Part of the Tree i.e. Pyramids.
for(int a = 1;a <= height ;a++){
for(int i = x;i <= width;i++){
for(int j = space;j >= i;j--){
System.out.print(" ");
}
for(int k = 1;k <= i;k++){
System.out.print("* ");
}
System.out.println();
}
x = x+2;
width = width+2;
}
//Printing Branch of Christmas Tree
for(int i = 1;i <= 4;i++){
for(int j = space-3;j >= 1;j--){
System.out.print(" ");
}
for(int k= 1;k <= 4;k++){
System.out.print("* ");
}
System.out.println();
}
}
}