Kotlin Program:

- To print half triangle pattern using alphabet

Example:

User Input: 3

Output:

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

  for(i in 1..rows) {
    c='A'
    for(j in 1..i) {
      print(c++ +" ")
    }
    println("")
  }
}

Output:

  Enter number of rows : 4
  A
  A B
  A B C
  A B C D
Program
pattern

Main logic :

for(i in 1..rows) {  //rows : number of rows to print
  c='A'
  for(j in 1..i) {
    print(c++ +" ")
  }
  println("")
}

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

Concept

Coming Soon !

Quick
Tutorial

Quote

Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.