TriangleUtilities.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. public class TriangleUtilities {
  2. public static String getRow(int numberOfStars) {
  3. StringBuilder builder = new StringBuilder();
  4. for(int i=1; i<=numberOfStars; i++){
  5. builder.append('*');
  6. }
  7. return builder.toString();
  8. }
  9. public static String getTriangle(int numberOfRows) {
  10. StringBuilder builder = new StringBuilder();
  11. for(int i=1; i<=numberOfRows; i++){
  12. String x = getRow(i);
  13. builder.append(x + "\n");
  14. }
  15. return builder.toString();
  16. }
  17. public static String getSmallTriangle() {
  18. StringBuilder builder = new StringBuilder();
  19. for(int i=1; i<=4; i++){
  20. String x = getRow(i);
  21. builder.append(x + "\n");
  22. }
  23. return builder.toString();
  24. }
  25. public static String getLargeTriangle() {
  26. StringBuilder builder = new StringBuilder();
  27. for(int i=1; i<=9; i++){
  28. String x = getRow(i);
  29. builder.append(x + "\n");
  30. }
  31. return builder.toString();
  32. }
  33. }