To print a hollow inverted pyramid pattern in Kotlin, we use nested loops to manage spaces and stars.
In this example,
fun main() {
val numRows = 5
for (row in numRows downTo 1) {
for (space in 0 until numRows - row) {
print(" ")
}
if (row == numRows || row == 1) {
repeat(2 * row - 1) {
print("*")
}
} else {
print("*")
repeat(2 * row - 3) {
print(" ")
}
print("*")
}
println()
}
}
********* * * * * * * *
In this tutorial, we learned How to print Hollow Inverted Pyramid Pattern in Kotlin language with well detailed examples.