TriangleUtilities.java 1.1KB

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