-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdvancedAstrology.java
43 lines (37 loc) · 1.3 KB
/
AdvancedAstrology.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
public class AdvancedAstrology {
public static String printStars(int number) {
String stars = "";
for(int i = 0; i < number; i++) {
stars += "*";
}
return stars;
}
public static String printSpaces(int number) {
String spaces = "";
for(int i = 0; i < number; i++) {
spaces += " ";
}
return spaces;
}
public static void printTriangle(int size) {
for(int i = 1; i <= size; i++) {
System.out.println(printSpaces((size - i)) + printStars(i) );
}
}
public static void christmasTree(int height) {
for (int i = 0; i < height; i++) {
System.out.println(printSpaces((height - (i + 1))) + printStars((i * 2)+ 1) + printSpaces(height - (i + 1)));
}
// System.out.println(printStars(2 * height - 1));
System.out.println(printSpaces(height - 2)+ "***" + printSpaces(height - 2));
System.out.println(printSpaces(height - 2)+ "***" + printSpaces(height - 2));
}
public static void main(String[] args) {
// The tests are not checking the main, so you can modify it freely.
printTriangle(5);
System.out.println("---");
christmasTree(4);
System.out.println("---");
christmasTree(10);
}
}