Kotlin Program:

- To print full triangle pattern using alphabet

Example:

User Input: 3

Output:

    A
  A B A
A B C B A
fun main(args: Array<String>) {
  print("Enter number of rows : ") 
  val userInput = readLine()!!
  var rows:Int =userInput.toInt()
  var c:Char

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

Output:

Enter number of rows: 4

      A
    A B A
  A B C B A
A B C D C B A
Program
pattern

Main Logic :

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

You can print the same pattern in small alphabets, just set c='a'

Concept

Coming Soon !

Quick
Tutorial

Quote

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