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