-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathTriangleUtilities.java
More file actions
46 lines (33 loc) · 1.17 KB
/
TriangleUtilities.java
File metadata and controls
46 lines (33 loc) · 1.17 KB
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
public class TriangleUtilities {
public static String getRow(int numberOfStars) {
String StarRow = "";
for (Integer i = 0; i < numberOfStars; i++) {
StarRow += "*";
}
return StarRow;
}
public static String getTriangle(int numberOfRows) {
String str1 = "";
//for each iteration of the loop, str1 concatenates with the output of the function
for (Integer i = 0; i < numberOfRows; i++) {
str1 += TriangleUtilities.getRow(i+1) + "\n";
}
return str1;
}
public static String getSmallTriangle() {
String SmallTri = "";
//same as getTriangle, but limited to 4 loops (0, 1, 2, 3)
for (Integer i = 0; i < 4; i++) {
SmallTri += TriangleUtilities.getRow(i+1) + "\n";
}
return SmallTri;
}
public static String getLargeTriangle() {
String LargeTri = "";
//same as getTriangle, but limited to 9 loops (0 - 8)
for (Integer i = 0; i < 9; i++) {
LargeTri += TriangleUtilities.getRow(i+1) + "\n";
}
return LargeTri;
}
}