TriangleUtilities.java 709B

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