TriangleUtilities.java 717B

12345678910111213141516171819202122232425262728293031323334353637
  1. import java.io.*;
  2. import java.util.*;
  3. import java.lang.*;
  4. public class TriangleUtilities {
  5. public static String getRow(int width) {
  6. String stars = "";
  7. for (int i=0; i<width; i++) {
  8. stars += "*";
  9. }
  10. return stars;
  11. }
  12. public static String getTriangle(int numberOfRows) {
  13. String stars = "";
  14. for (int i=0; i<numberOfRows; i++) {
  15. for (int b=0; b<=i; b++) {
  16. stars += "*";
  17. }
  18. stars+= "\n";
  19. }
  20. return stars;
  21. }
  22. public static String getSmallTriangle() {
  23. return getTriangle(4);
  24. }
  25. public static String getLargeTriangle() {
  26. return getTriangle(9);
  27. }
  28. }