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