12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
-
-
- public class TriangleUtilities {
-
- public static String getRow(int numberOfStars) {
- StringBuilder sb = new StringBuilder();
- //String str = "";
- for (int i =0; i < numberOfStars; i++){
- //str += "*";
- sb = sb.append("*");
- }
- //return str;
- return sb.toString();
- }
-
- public static String getTriangle(int numberOfRows) {
- StringBuilder sb = new StringBuilder();
-
- for (int i = 0; i < numberOfRows; i++) {
-
- for (int j = 0; j <= i; j++)
- {
- //if (j<i)
-
- sb = sb.append("*");
- }
- sb.append("\n");
- }
-
- return sb.toString();
- }
-
-
- public static String getSmallTriangle() {
- StringBuilder sb = new StringBuilder();
-
- for (int i = 0; i < 4; i++) {
-
- for (int j = 0; j <= i; j++)
- {
- //if (j<i)
-
- sb.append("*");
- }
- sb.append("\n");
- }
-
-
- System.out.print(sb);
- return sb.toString();
- }
-
- public static String getLargeTriangle() {
- StringBuilder sb = new StringBuilder();
-
- for (int i = 0; i < 9; i++) {
-
- for (int j = 0; j <= i; j++)
- {
- //if (j<i)
-
- sb.append("*");
- }
- sb.append("\n");
- }
-
-
- System.out.print(sb);
- return sb.toString();
- }
-
- }
|