-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintingLikeBoss.java
65 lines (56 loc) · 1.58 KB
/
PrintingLikeBoss.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
public class PrintingLikeBoss {
// copy or rewrite the method of Assignment 39.1 here
public static void printStars(int amount) {
int counter = 1;
while (counter <= amount){
System.out.print("*");
counter++;
}
System.out.println();
}
public static void printWhitespaces(int amount) {
int counter = 1;
while (counter <= amount){
System.out.print(" ");
counter++;
}
// 40.1
}
public static void printTriangle(int size) {
int counter = 1;
int tempSize = size - 1;
while (counter <= size){
printWhitespaces(tempSize);
printStars(counter);
tempSize--;
counter++;
}
// printWhitespaces(size - 1);
// printStarts()
// 40.2
}
public static void xmasTree(int height) {
int counter = 1;
int tempCounter = height - 1;
int starCounter = 1;
while (counter <= height){
printWhitespaces(tempCounter);
printStars(starCounter);
tempCounter--;
counter++;
starCounter += 2;
}
printWhitespaces(height - 2);
printStars(3);
printWhitespaces(height - 2);
printStars(3);
// 40.3
}
public static void main(String[] args) {
// Tests do not use main, yo can write code here freely!
System.out.println("---");
xmasTree(4);
System.out.println("---");
xmasTree(10);
}
}