TriangleUtilities.java 709B

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