1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. public class TriangleUtilities {
  2. public static String getRow(int numberOfStars) {
  3. StringBuilder stringStars = new StringBuilder();
  4. for (int i = 0; i < numberOfStars; i++) {
  5. stringStars.append("*");
  6. }
  7. return stringStars.toString();
  8. }
  9. public static String getTriangle(int numberOfRows) {
  10. StringBuilder strStars = new StringBuilder();
  11. for (int i = 0; i <numberOfRows; i++)
  12. {
  13. for (int j = 0; j <= i; j++)
  14. {
  15. if (j<=i)
  16. strStars.append("*");
  17. }
  18. strStars.append("\n");
  19. }
  20. return strStars.toString();
  21. }
  22. public static String getSmallTriangle() {
  23. StringBuilder strStars = new StringBuilder();
  24. for (int i = 0; i <4; i++)
  25. {
  26. for (int j = 0; j <= i; j++)
  27. {
  28. if (j<=i)
  29. strStars.append("*");
  30. }
  31. strStars.append("\n");
  32. }
  33. return strStars.toString();
  34. }
  35. public static String getLargeTriangle() {
  36. StringBuilder strStars = new StringBuilder();
  37. for (int i = 0; i <9; i++) {
  38. for (int j = 0; j <= i; j++) {
  39. if (j<=i) {
  40. strStars.append("*");
  41. }
  42. }
  43. strStars.append("\n");
  44. }
  45. return strStars.toString();
  46. }
  47. }