TriangleUtilities.java 1.0KB

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