TriangleUtilities.java 709B

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