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