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