TriangleUtilities.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. public class TriangleUtilities {
  2. public static String getRow(int numberOfStars) {
  3. int counter = 1;
  4. String triangle = "";
  5. String add = "*";
  6. for (int i = 1; i <= numberOfStars; i++){
  7. triangle = triangle + add;
  8. }
  9. return triangle;
  10. }
  11. public static String getTriangle(int numberOfRows) {
  12. int counter = 1;
  13. String triangle = "";
  14. String add = "*";
  15. for (int i = 1; i <= numberOfRows; i++){
  16. for (int y = 1; y <= counter; y++){
  17. triangle = triangle + add;
  18. }
  19. counter++;
  20. triangle = triangle + System.getProperty("line.separator");
  21. }
  22. return triangle;
  23. }
  24. public static String getSmallTriangle() {
  25. int width = 4;
  26. int counter = 1;
  27. String triangle = "";
  28. String add = "*";
  29. for (int i = 1; i <= width; i++){
  30. for (int y = 1; y <= counter; y++){
  31. triangle = triangle + add;
  32. }
  33. counter++;
  34. triangle = triangle + System.getProperty("line.separator");
  35. }
  36. return triangle;
  37. }
  38. public static String getLargeTriangle() {
  39. int width = 9;
  40. int counter = 1;
  41. String triangle = "";
  42. String add = "*";
  43. for (int i = 1; i <= width; i++){
  44. for (int y = 1; y <= counter; y++){
  45. triangle = triangle + add;
  46. }
  47. counter++;
  48. triangle = triangle + System.getProperty("line.separator");
  49. }
  50. return triangle;
  51. }
  52. }