12345678910111213141516171819202122232425262728293031323334353637
  1. public class TriangleUtilities {
  2. public static String getRow(int numberOfStars) {
  3. String row = "";
  4. for(int i=0; i<numberOfStars; i++) {
  5. row = row + "*"; //row+="*"
  6. }
  7. return row;
  8. }
  9. public static String getTriangle(int numberOfRows) {
  10. String triangle = "";
  11. for (int i=0; i<numberOfRows; i++) {
  12. if (numberOfRows == 1) { // special case
  13. return "*";
  14. }
  15. triangle = triangle + getRow(i+1);
  16. triangle = triangle + "\n";
  17. }
  18. return triangle;
  19. }
  20. public static String getSmallTriangle() {
  21. return getTriangle(4);
  22. }
  23. public static String getLargeTriangle() {
  24. return getTriangle(9);
  25. }
  26. }