Print Pyramid Triangle Star (*) in Kotlin
Today we are going to know how to make Pyramid Pattern in Kotlin. This is Advance level in forloop, However if you are begineer you have to read Simple forloop with Star, You will get an idea with this.
Expected Output :
*
* *
* * *
* * * *
we need three forloop .
First Forloop is for rows : Like we are need 4 rows
Second forloop is for Spaces . You can see the spaces in every Rows, like in first row we need three spaces and in second row we need 2 spaces and so on ,
Third forloop is for Printing Star. So start coding. Its fun….
fun printPyramid(){
var n = 5
for(i in 0 until n){
for(j in 0 until n-i){
print(" ")
}
for(k in 0 until i){
print("* ")
}
println("")
}
}
Above is the function, we need to print Star in Pyramid Way. We have used 3 forloop.
You can read other articles also on forloop
Hope You liked the Articles.