⚡ TL;DR
Print the solid square star pattern in Go. Complete working code, expected output, algorithm explanation, and practice variations for beginners.
The Solid Square Star pattern is a fundamental loop exercise for Go beginners. Here’s the complete implementation with working code and output.
Pattern to Print
*****
*****
*****
*****
*****Implementation
package main
import ("fmt"; "strings")
func main() {
n := 5
for i := 0; i < n; i++ {
fmt.Println(strings.Repeat("*", n))
}
}Output
*****
*****
*****
*****
*****How It Works
n rows, each containing n stars. The simplest nested-loop pattern — the foundation for all grid patterns.
Practice Variations
- Try printing the pattern with a different character (e.g.,
#or+) - Modify the code to accept the pattern size as user input
- Combine this pattern with its inverse to create a diamond or hourglass
Complexity
- Time: O(n²) — total characters printed grows quadratically
- Space: O(n) — longest row is O(n) characters
Related Patterns
- Solid Square Star in Python
- Solid Square Star in Dart
- Solid Square Star in Swift
- Cross/Plus Sign Star in Go
- Christmas Tree Star in Go
- Up Arrow Star in Go
FAQ
How do you print the Solid Square Star pattern in Go?
Use nested loops: the outer loop walks through the rows while the inner loop prints the characters or values for each row. The complete Go implementation with expected output is shown in the sections above.
What is the time complexity of the Solid Square Star pattern in Go?
The time complexity is O(n²) and the space complexity is O(n), since the pattern is built with a fixed number of loop counters and printed row by row.
Happy coding!
