⚡ TL;DR
Print the star of david pattern in Dart with working code and output. Working implementation, sample run, and complexity analysis included.
The Star of David pattern is a classic loop exercise. Here’s the complete implementation in Dart with working code and output.
Pattern to Print
*************
* * * *
* * * *
* *
* * * *
* * * *
*************Implementation
void main() {
int n = 4;
int height = 2 * n - 1;
int width = 4 * n - 3;
for (int r = 0; r < height; r++) {
if (r == 0 || r == height - 1) {
print('*' * width);
continue;
}
List<String> cells = List<String>.filled(width, ' ');
int loUp = (width - (2 * r + 1)) ~/ 2;
cells[loUp] = '*';
cells[loUp + 2 * r] = '*';
int d = height - 1 - r;
int loDn = (width - (2 * d + 1)) ~/ 2;
cells[loDn] = '*';
cells[loDn + 2 * d] = '*';
print(cells.join().trimRight());
}
}Output
*************
* * * *
* * * *
* *
* * * *
* * * *
*************How It Works
Two triangle outlines are drawn on one grid: an upward triangle whose rows widen 1, 3, 5… from the top apex, and a downward triangle that narrows toward the bottom apex. The top and bottom rows are the solid bases; every row between prints only the two edge stars of each triangle.
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 more complex shape
Complexity
- Time: O(n²) — the grid or line count grows quadratically
- Space: O(n²) — the grid is stored before printing
FAQ
How do you print the Star of David pattern in Dart?
Use nested loops: the outer loop walks through the rows while the inner loop prints the characters or values for each row. The complete Dart implementation with expected output is shown in the sections above.
What is the time complexity of the Star of David pattern in Dart?
The time complexity is O(n²) and the space complexity is O(n²), since the pattern is built on a grid that is filled first and then printed row by row.
Happy coding!

Written by Mihir Pipermitwala
Senior Full Stack Consultant & Mobile Engineering Specialist building user-focused applications in healthcare with Flutter, Dart and React Native. I write about what I actually build and test — every tutorial here comes from real project work.
More about Mihir →