12345678910111213141516171819202122232425262728293031323334353637 |
-
-
- public class TriangleUtilities {
-
- public static String getRow(int numberOfStars) {
- String row = "";
-
- for(int i=0; i<numberOfStars; i++) {
- row = row + "*"; //row+="*"
- }
- return row;
- }
-
- public static String getTriangle(int numberOfRows) {
- String triangle = "";
-
- for (int i=0; i<numberOfRows; i++) {
- if (numberOfRows == 1) { // special case
- return "*";
- }
-
- triangle = triangle + getRow(i+1);
- triangle = triangle + "\n";
- }
- return triangle;
- }
-
-
- public static String getSmallTriangle() {
- return getTriangle(4);
- }
-
- public static String getLargeTriangle() {
- return getTriangle(9);
- }
- }
|