TriangleUtilities.java 770B

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