Skip to content

Commit

Permalink
Merge pull request #5 from 6736-shafi/master
Browse files Browse the repository at this point in the history
added Triangle Star Pattern
  • Loading branch information
Yashkapure06 authored Oct 4, 2023
2 parents b4989b3 + f752fb0 commit 89e19d0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,16 @@
* *
* *
* *
```
14.Triangle Star Pattern
```
*
* *
* *
* *
* *
* *
* *
* *
*****************
```
32 changes: 32 additions & 0 deletions src/TriangleStarPattern/TriangleStarPattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package TriangleStarPattern;

public class TriangleStarPattern {

public static void main(String[] args) {
// Declare variables i, j, k, and set the number of rows to 9
int i, j, k, rows = 9;

// Loop through rows from 1 to 9
for (i = 1; i <= rows; i++) {
// Print spaces before the pattern to center it
for (j = i; j < rows; j++) {
System.out.print(" ");
}

// Loop to print the pattern for the current row
for (k = 1; k <= (2 * i - 1); k++) {
// If it's the first character, last character, or the bottom row, print '*'
if (k == 1 || i == rows || k == (2 * i - 1)) {
System.out.print("*");
} else {
// Otherwise, print a space to create the hollow pattern
System.out.print(" ");
}
}

// Move to the next line for the next row this will addd new line in the pattern
System.out.println("");
}

}
}

0 comments on commit 89e19d0

Please sign in to comment.