TriangleUtilities.java 690B

123456789101112131415161718192021222324252627282930313233
  1. public class TriangleUtilities {
  2. public static String getRow(int numberOfStars) {
  3. String width = "";
  4. for (int i = 0; i < numberOfStars; i++){
  5. width += "*";
  6. }
  7. return width;
  8. }
  9. public static String getTriangle(int numberOfRows) {
  10. String triangle = "";
  11. for (int i = 1; i <= numberOfRows; i++){
  12. for (int b = 1; b <= i; b++){
  13. triangle += "*";
  14. }
  15. triangle += "\n";
  16. }
  17. return triangle;}
  18. public static String getSmallTriangle() {
  19. return getTriangle(4);
  20. }
  21. public static String getLargeTriangle() {
  22. return getTriangle(9);
  23. }
  24. }