TriangleUtilities.java 1.1KB

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