-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from 6736-shafi/master
added Triangle Star Pattern
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,4 +141,16 @@ | |
* * | ||
* * | ||
* * | ||
``` | ||
14.Triangle Star Pattern | ||
``` | ||
* | ||
* * | ||
* * | ||
* * | ||
* * | ||
* * | ||
* * | ||
* * | ||
***************** | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(""); | ||
} | ||
|
||
} | ||
} |