-
Notifications
You must be signed in to change notification settings - Fork 8
/
PrintingLikeBoss.java
65 lines (57 loc) · 1.47 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) {
// 39.1
// you can print one star with the command
// System.out.print("*");
// call this command amount times
int i = 0;
while (i < amount){
System.out.print("*");
i++;
}
System.out.println();
}
public static void printWhitespaces(int amount) {
// 40.1
int i = 0;
while (i < amount){
System.out.print(" ");
i++;
}
}
public static void printTriangle(int size) {
// 40.2
int i = 1;
while (i <= size){
printWhitespaces(size-i);
printStars(i);
i++;
}
}
public static void xmasTree(int height) {
// 40.3
int i = 1;
int j = 1;
while (j <= height){
printWhitespaces(height-j);
printStars(i);
i += 2;
j++;
}
int k = 0;
while (k < 2){
printWhitespaces(height-2);
printStars(3);
k++;
}
}
public static void main(String[] args) {
// Tests do not use main, yo can write code here freely!
printTriangle(5);
System.out.println("---");
xmasTree(4);
System.out.println("---");
xmasTree(10);
}
}