TriangleUtilities.java 1.1KB

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