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