TriangleUtilities.java 1.1KB

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