To print a hollow inverted pyramid pattern in Dart, we use nested loops to manage spaces and stars.
In this example,
void printHollowInvertedPyramid(int numRows) {
for (int row = numRows; row >= 1; row--) {
String pattern = '';
for (int space = 0; space < numRows - row; space++) {
pattern += ' ';
}
if (row == numRows || row == 1) {
pattern += '*'.padRight(2 * row - 1, '*');
} else {
pattern += '*';
pattern += ' '.padRight(2 * row - 3, ' ');
pattern += '*';
}
print(pattern);
}
}
void main() {
printHollowInvertedPyramid(5);
}
********* * * * * * * *
In this tutorial, we learned How to print Hollow Inverted Pyramid Pattern in Dart language with well detailed examples.