logoStarPatterns
Back to Patterns

Diamond Star Pattern

Pattern Result

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

Code Implementation

Explanation

The Diamond Star Pattern creates a diamond shape using asterisks with spaces between them. The pattern consists of two halves: the upper half where the number of stars increases from 1 to n, and the lower half where it decreases from n-1 back to 1. Each row is properly aligned by adding spaces before the stars. The algorithm uses nested loops to create the pattern: separate outer loops handle the upper and lower halves, while the inner loops handle the spaces and stars in each row.