Kotlin Program:

- To print sideway reverse triangle pattern using *

Example:

User Input: 3

Output:

    *
  * *
* * *
  * *
    *
fun main(args: Array<String>) {
  print("Enter number of columns : ") 
  val userInput = readLine()!!
  var columns:Int =userInput.toInt()
  var trows:Int
  var k:Int

  trows=2*columns-1
  k=trows
  for(i in trows downTo 1) {
    for(j in 1..trows) {
      if(j<k)print("  ")
      else print("* ")
    }
    if(i<=columns)k++;
    else k--;

    println("")
  }
}

Output:

Enter number of columns: 4

      *
    * *
  * * *
* * * *
  * * *
    * *
      *
Program
pattern

Main Logic :

trows=2*columns-1   // trows : total rows to print
k=trows  // Used to trigger decreasing order of *
for(i in trows downTo 1) {
  for(j in 1..trows) {
    if(j<k)print("  ")
    else print("* ")
  }

//check for position change at which triangle * value to decrease
  if(i<=columns)k++;
  else k--;
  
  println("")
}

You can print any thing in this pattern, just replace your value with *

Concept

Coming Soon !

Quick
Tutorial

Quote

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