logoStarPatterns
Back to Patterns

Hollow Reverse Triangle Pattern

Pattern Result

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

Code Implementation

Explanation

The Hollow Reverse Triangle Pattern creates an inverted triangle shape where only the border is visible, except for the first row which is filled with stars. For each row except the first, we place stars only at the first and last positions, with spaces in between to create the hollow effect. The first row is completely filled with stars to form the base of the inverted triangle. The outer loop iterates from n down to 1, representing each row. For each row, we handle three cases: the first position (always a star), the middle positions (spaces for hollow effect), and the last position (a star if it's not the last row).