TriangleUtilities.java 1.1KB

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