TriangleUtilities.java 1.0KB

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