TriangleUtilities.java 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import java.lang.StringBuilder;
  2. public class TriangleUtilities {
  3. public static String getRow(int numberOfStars) {
  4. StringBuilder sb = new StringBuilder();
  5. for (int i = 0; i < numberOfStars; i++) {
  6. sb.append("*");
  7. }
  8. return sb.toString();
  9. }
  10. public static String getTriangle(int numberOfRows) {
  11. StringBuilder sb = new StringBuilder();
  12. for (int i = 0; i < numberOfRows; i++) {
  13. sb.append(getRow(i+1));
  14. sb.append("\n");
  15. }
  16. return sb.toString();
  17. }
  18. public static String getSmallTriangle() {
  19. StringBuilder sb = new StringBuilder();
  20. for (int i = 0; i < 4; i++) {
  21. sb.append(getRow(i+1));
  22. sb.append("\n");
  23. }
  24. System.out.println(sb.toString());
  25. return sb.toString();
  26. }
  27. public static String getLargeTriangle() {
  28. StringBuilder sb = new StringBuilder();
  29. for (int i = 0; i < 9; i++) {
  30. sb.append(getRow(i+1));
  31. sb.append("\n");
  32. }
  33. return sb.toString();
  34. }
  35. }