1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import java.lang.StringBuilder;
-
- public class TriangleUtilities {
-
- public static String getRow(int numberOfStars) {
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < numberOfStars; i++) {
- sb.append("*");
- }
- return sb.toString();
- }
-
- public static String getTriangle(int numberOfRows) {
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < numberOfRows; i++) {
- sb.append(getRow(i+1));
- sb.append("\n");
- }
- return sb.toString();
- }
-
-
- public static String getSmallTriangle() {
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 4; i++) {
- sb.append(getRow(i+1));
- sb.append("\n");
- }
- System.out.println(sb.toString());
- return sb.toString();
- }
-
-
- public static String getLargeTriangle() {
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 9; i++) {
- sb.append(getRow(i+1));
- sb.append("\n");
- }
- return sb.toString();
- }
- }
|