TriangleUtilities.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 <= 4; 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 <= 9; i++){
  32. for (int j = 1; j <= i; j++){
  33. triangle += "*";
  34. }
  35. triangle += "\n";
  36. }
  37. return triangle;
  38. }
  39. }