|
@@ -3,18 +3,78 @@ package io.zipcoder.microlabs.mastering_loops;
|
3
|
3
|
public class TriangleUtilities {
|
4
|
4
|
|
5
|
5
|
public static String getTriangle(int numberOfRows) {
|
6
|
|
- return null;
|
|
6
|
+
|
|
7
|
+ StringBuilder outcome = new StringBuilder();
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+ for (int i=1; i < numberOfRows; i++) {
|
|
11
|
+
|
|
12
|
+ for (int j=0; j < i; j++){
|
|
13
|
+
|
|
14
|
+ outcome.append("*");
|
|
15
|
+ }
|
|
16
|
+ outcome.append("\n");
|
|
17
|
+
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+ return outcome.toString();
|
7
|
22
|
}
|
8
|
23
|
|
9
|
24
|
public static String getRow(int numberOfStars) {
|
10
|
|
- return null;
|
|
25
|
+
|
|
26
|
+ StringBuilder outcome = new StringBuilder();
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+ for (int i=0; i < numberOfStars; i++){
|
|
30
|
+
|
|
31
|
+ outcome.append("*");
|
|
32
|
+
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+ return outcome.toString();
|
11
|
37
|
}
|
12
|
38
|
|
13
|
39
|
public static String getSmallTriangle() {
|
14
|
|
- return null;
|
|
40
|
+ StringBuilder outcome = new StringBuilder();
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+ for (int i=1; i <=4; i++) {
|
|
44
|
+
|
|
45
|
+ for (int j=0; j < i; j++){
|
|
46
|
+
|
|
47
|
+ outcome.append("*");
|
|
48
|
+ }
|
|
49
|
+ outcome.append("\n");
|
|
50
|
+
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+ return outcome.toString();
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
15
|
58
|
}
|
16
|
59
|
|
17
|
60
|
public static String getLargeTriangle() {
|
18
|
|
- return null;
|
|
61
|
+
|
|
62
|
+ StringBuilder outcome = new StringBuilder();
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+ for (int i=1; i <=9; i++) {
|
|
66
|
+
|
|
67
|
+ for (int j=0; j < i; j++){
|
|
68
|
+
|
|
69
|
+ outcome.append("*");
|
|
70
|
+ }
|
|
71
|
+ outcome.append("\n");
|
|
72
|
+
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+ return outcome.toString();
|
|
77
|
+
|
|
78
|
+
|
19
|
79
|
}
|
20
|
80
|
}
|