TriangleUtilities.java 1.3KB

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