Print Pyramid Triangle Star (*) in Kotlin

Jaspreet Singh
McAppMedia
Published in
1 min readOct 7, 2019

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

Print RightTriangle

Print Left Triangle

Hope You liked the Articles.

--

--

Jaspreet Singh
McAppMedia

Working in Android Developemen and Tech Mentor .My Github profile is: https://github.com/jaspreet1990 , Contact me at preetjaspreet90@gmail.com for more info.