forked from Zipcoder/BlueJ.NumbersTrianglesTables
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangleUtilities.java
More file actions
41 lines (30 loc) · 940 Bytes
/
TriangleUtilities.java
File metadata and controls
41 lines (30 loc) · 940 Bytes
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
public class TriangleUtilities {
public static String getRow(Integer numberOfStars) {
String stars = "*";
String row = stars.repeat(numberOfStars);
/*for(int i = 1; i <= numberOfStars; i++){
row += "*";
}*/
return row;
}
public static String getTriangle(int numberOfRows) {
//Removed the nested FOR loop
StringBuilder sb = new StringBuilder();
String stars = "*";
for(int i = 1; i <= numberOfRows; i++){
sb.append(stars.repeat(i));
sb.append("\n");
/*(int i = 1; i <= numberOfRows; i++){
triangle += getRow(i);
triangle += "\n";
}*/
}
return sb.toString();
}
public static String getSmallTriangle() {
return getTriangle(4);
}
public static String getLargeTriangle() {
return getTriangle(9);
}
}