TriangleUtilities.java 1.2KB

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