TriangleUtilities.java 720B

123456789101112131415161718192021222324252627282930
  1. public class TriangleUtilities {
  2. public static String getRow(int numberOfStars) {
  3. StringBuilder stars = new StringBuilder();
  4. for (int i = 0; i < numberOfStars; i++) stars.append("*");
  5. return stars.toString();
  6. }
  7. public static String getTriangle(int numberOfRows) {
  8. StringBuilder stars = new StringBuilder();
  9. for (int i = 1; i <= numberOfRows; i++) {
  10. stars.append(getRow(i) + "\n");
  11. //return row.toString();
  12. }
  13. return stars.toString();
  14. }
  15. public static String getSmallTriangle() {
  16. return getTriangle(4);
  17. }
  18. public static String getLargeTriangle() {
  19. return getTriangle(9);
  20. }
  21. }