|
@@ -4,46 +4,27 @@ public class TriangleUtilities {
|
4
|
4
|
|
5
|
5
|
public static String getTriangle(int numberOfRows) {
|
6
|
6
|
StringBuilder builder = new StringBuilder();
|
7
|
|
- for (int row = 1; row < numberOfRows; row++) {
|
8
|
|
- for (int col = 0; col < row; col++) {
|
9
|
|
- builder.append("*");
|
10
|
|
- }
|
11
|
|
- builder.append("\n");
|
|
7
|
+ for (int row = 0; row < numberOfRows; row++) {
|
|
8
|
+ builder.append(getRow(row));
|
12
|
9
|
}
|
13
|
|
-
|
14
|
10
|
return builder.toString();
|
15
|
|
-
|
16
|
11
|
}
|
17
|
12
|
|
18
|
13
|
public static String getRow(int numberOfStars) {
|
19
|
|
- String asterisk = "";
|
20
|
|
- for (int i = 0; i < numberOfStars; i++) {
|
21
|
|
- asterisk += "*";
|
|
14
|
+ StringBuilder builder = new StringBuilder();
|
|
15
|
+
|
|
16
|
+ for (int i = 0; i <= numberOfStars; i++) {
|
|
17
|
+ builder.append("*");
|
22
|
18
|
}
|
23
|
|
- return asterisk;
|
|
19
|
+ builder.append("\n");
|
|
20
|
+ return builder.toString();
|
24
|
21
|
}
|
25
|
22
|
|
26
|
23
|
public static String getSmallTriangle() {
|
27
|
|
- StringBuilder builder = new StringBuilder();
|
28
|
|
- for (int row = 1; row <= 4; row++) {
|
29
|
|
- for (int col = 0; col < row; col++) {
|
30
|
|
- builder.append("*");
|
31
|
|
- }
|
32
|
|
- builder.append("\n");
|
33
|
|
- }
|
34
|
|
-
|
35
|
|
- return builder.toString();
|
|
24
|
+ return getTriangle(4);
|
36
|
25
|
}
|
37
|
26
|
|
38
|
27
|
public static String getLargeTriangle() {
|
39
|
|
- StringBuilder builder = new StringBuilder();
|
40
|
|
- for (int row = 1; row <= 9; row++) {
|
41
|
|
- for (int col = 0; col < row; col++) {
|
42
|
|
- builder.append("*");
|
43
|
|
- }
|
44
|
|
- builder.append("\n");
|
45
|
|
- }
|
46
|
|
-
|
47
|
|
- return builder.toString();
|
|
28
|
+ return getTriangle(9);
|
48
|
29
|
}
|
49
|
30
|
}
|