TriangleUtilities.java 1.2KB

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