To print a pyramid pattern in Kotlin, you can use nested loops where the outer loop controls the rows and the inner loop controls the spaces and stars printed in each row.
In this example,
n
to represent the number of rows in the pyramid.println()
to move to the next line.fun main() {
val n = 5
for (i in 1..n) {
for (j in 1..n - i) {
print(' ')
}
for (k in 1..2 * i - 1) {
print('*')
}
println()
}
}
* *** ***** ******* *********
In this tutorial, we learned How to print Pyramid Pattern in Kotlin language with well detailed examples.