logoStarPatterns
Back to Patterns

Pyramid Pattern

Pattern Result

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

Code Implementation

Explanation

The Pyramid Pattern creates a triangle shape that resembles a pyramid. For each row, the number of stars increases by 2, starting with 1 star at the top. The stars are centered by adding spaces before and after them. The formula for the number of stars in each row is (2 * rowIndex + 1), and the number of spaces on each side is (totalRows - rowIndex - 1).