TriangleUtilities.java 956B

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