TriangleUtilities.java 789B

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