1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
-
-
- public class TriangleUtilities {
-
- public static String getRow(int numberOfStars) {
- StringBuilder stringStars = new StringBuilder();
- for (int i = 0; i < numberOfStars; i++) {
- stringStars.append("*");
- }
- return stringStars.toString();
- }
-
- public static String getTriangle(int numberOfRows) {
- StringBuilder strStars = new StringBuilder();
- for (int i = 0; i <numberOfRows; i++)
- {
- for (int j = 0; j <= i; j++)
- {
- if (j<=i)
- strStars.append("*");
- }
- strStars.append("\n");
- }
- return strStars.toString();
- }
- public static String getSmallTriangle() {
- StringBuilder strStars = new StringBuilder();
- for (int i = 0; i <4; i++)
- {
- for (int j = 0; j <= i; j++)
- {
- if (j<=i)
- strStars.append("*");
- }
- strStars.append("\n");
- }
- return strStars.toString();
- }
-
- public static String getLargeTriangle() {
- StringBuilder strStars = new StringBuilder();
- for (int i = 0; i <9; i++) {
- for (int j = 0; j <= i; j++) {
- if (j<=i) {
- strStars.append("*");
- }
- }
- strStars.append("\n");
- }
- return strStars.toString();
- }
- }
|