1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- public class TriangleUtilities {
-
- public static String getRow(int numberOfStars) {
- StringBuilder asterisks = new StringBuilder();
-
- for (int i = 1; i <= numberOfStars; i++) {
- asterisks.append("*");
- }
- return asterisks.toString();
- }
-
- public static String getTriangle(int numberOfRows) {
- StringBuilder asterisks = new StringBuilder();
-
- for (int i = 1; i <= numberOfRows; i++) {
- for (int j = 1; j <= i; j++) {
- asterisks.append("*");
- }
- asterisks.append("\n");
- }
- return asterisks.toString();
- }
-
- public static String getSmallTriangle() {
- StringBuilder asterisks = new StringBuilder();
-
- for (int i = 1; i <= 4; i++) {
- for (int j = 1; j <= i; j++) {
- asterisks.append("*");
- }
- asterisks.append("\n");
- }
- return asterisks.toString();
- }
-
- public static String getLargeTriangle() {
- StringBuilder asterisks = new StringBuilder();
-
- for (int i = 1; i < 10; i++) {
- for (int j = 1; j <= i; j++) {
- asterisks.append("*");
- }
- asterisks.append("\n");
- }
- return asterisks.toString();
- }
- }
|