Kotlin Program:

- To print full triangle pattern using number

Example:

User Input: 3

Output:

    1
  1 2 1
1 2 3 2 1
fun main(args: Array<String>) {
  print("Enter number of rows : ") 
  val userInput = readLine()!!
  var rows:Int =userInput.toInt()
  var k:Int

  for(i in rows downTo 1) {
    k=1
    for(j in 1..(2*rows-i)) {
      if(j<i)print("  ")
      else {
        if(j<rows)print("${k++} ")
        else print("${k--} ")
      }
    }
    println("")
  }
}

Output:

Enter number of rows: 4

      1
    1 2 1
  1 2 3 2 1
1 2 3 4 3 2 1
Program
pattern

Main Logic :

for(i in rows downTo 1) {
  k=1
  for(j in 1..(2*rows-i)) {
    if(j<i)print("  ")
    else {
      if(j<rows)print("${k++} ")
      else print("${k--} ")
    }
  }
  println("")
}
Concept

Coming Soon !

Quick
Tutorial

Quote

Sometimes it’s the smallest decisions that can change your life forever.