forked from jarekPierchala/SierpinskiChallenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HollowEquiTriangle.java
34 lines (28 loc) · 961 Bytes
/
HollowEquiTriangle.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
public class HollowEquiTriangle {
public static void main(String[] args) {
int height = 4; // height
int star = 1;
int space = height - 1;
// Print the equilateral triangle
for (int i = 1; i <= height; i++) {
// Print spaces before the '*' to create the triangular shape
for (int j = 1; j <= space; j++) {
System.out.print(" ");
}
// Print '*' for the first and last column in each row
for (int j = 1; j <= star; j++) {
if(i == height){
System.out.print("*");
}else if (j == 1 || j == star) {
System.out.print("*");
}else {
System.out.print(" ");
}
}
space--;
star += 2;
// Move to the next line after each row
System.out.println();
}
}
}