Back to Patterns
Hollow Triangle Pattern
Pattern Result
** ** ** **********
Code Implementation
Explanation
The Hollow Triangle Pattern creates a triangle shape where only the border is visible, except for the last row which is filled with stars. For each row except the last, we place stars only at the first and last positions, with spaces in between to create the hollow effect. The last row is completely filled with stars to form the base of the triangle. The outer loop iterates from 1 to n, 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 first row).