The logic is identical, just replace 'row == n' with 'row == height' and 'col == n' with 'col == width'.
Printing a Hollow Square Star Pattern
How do I make a hollow rectangle?
The answer
More FAQs in Printing a Hollow Square Star Pattern
Generate an N x N grid and print a star only if the current row or column is at the absolute boundary (1 or N). Otherwise, print a space.
You could, but it is incredibly messy. Coordinate-based boolean logic is the standard and most readable way to handle hollow shapes.
Because terminal fonts are usually taller than they are wide. A star (*) takes up more vertical space than horizontal space. You can fix this by printing '* ' (with a space) to widen the shape.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.