To print the Left Half Pyramid Pattern in Kotlin, we use nested loops where the outer loop controls the rows and the inner loop prints spaces and stars.
In this example,
n
, which is set to 5 in this example.n
, controlling the number of rows.n
and the current row, followed by stars equal to the current row number.fun main() {
val n = 5
for (i in 1..n) {
for (j in 1..n - i) {
print(" ")
}
for (k in 1..i) {
print("*")
}
println()
}
}
* ** *** **** *****
In this tutorial, we learned How to print Left Half Pyramid Pattern in Kotlin language with well detailed examples.