|
@@ -17,17 +17,48 @@ public class TriangleUtilities {
|
17
|
17
|
}
|
18
|
18
|
|
19
|
19
|
public static String getTriangle(int numberOfRows) {
|
20
|
|
- // numberOfRows -1 for each row
|
21
|
|
- // for loop for # of rows, decreasing by 1
|
22
|
|
- return
|
|
20
|
+ StringBuilder stars = new StringBuilder();
|
|
21
|
+
|
|
22
|
+ for (int i = 1; i <= numberOfRows; i++) {
|
|
23
|
+ for (int j = i; j > 0; j--) {
|
|
24
|
+ stars.append("*");
|
|
25
|
+ }
|
|
26
|
+ stars.append("\n");
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ String starTriangle = stars.toString();
|
|
30
|
+ return starTriangle;
|
|
31
|
+
|
23
|
32
|
}
|
24
|
33
|
|
25
|
34
|
|
26
|
35
|
public static String getSmallTriangle() {
|
27
|
|
- return null;
|
28
|
|
- }
|
|
36
|
+ StringBuilder stars = new StringBuilder();
|
|
37
|
+
|
|
38
|
+ for (int i = 1; i < 5; i++) {
|
|
39
|
+ for (int j = i; j > 0; j--) {
|
|
40
|
+ stars.append("*");
|
|
41
|
+ }
|
|
42
|
+ stars.append("\n");
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ String starTriangle = stars.toString();
|
|
46
|
+ return starTriangle;
|
|
47
|
+
|
|
48
|
+ }
|
29
|
49
|
|
30
|
50
|
public static String getLargeTriangle() {
|
31
|
|
- return null;
|
|
51
|
+ StringBuilder stars = new StringBuilder();
|
|
52
|
+
|
|
53
|
+ for (int i = 1; i < 10 ; i++) {
|
|
54
|
+ for (int j = i; j > 0; j--) {
|
|
55
|
+ stars.append("*");
|
|
56
|
+ }
|
|
57
|
+ stars.append("\n");
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ String starTriangle = stars.toString();
|
|
61
|
+ return starTriangle;
|
|
62
|
+
|
32
|
63
|
}
|
33
|
64
|
}
|