Kotlin Program:

- To print half opposite triangle pattern using *

Example:

User Input: 4

Output:

* * * *
  * * *
    * *
      *
fun main(args: Array<String>) {
  print("Enter number of rows : ") 
  val userInput = readLine()!!
  var rows:Int =userInput.toInt()
  for(i in 1..rows) {
    for(j in 1..rows) {
      if(j<i)print("  ")
      else print("* ")
    }
    println("")
  }
}

Output:

  Enter number of rows : 4
  * * * *
    * * *
      * *
        *
Program
pattern

Main logic :

for(i in 1..rows) {  //rows : number of rows to print
  for(j in 1..rows) {
    if(j<i)print("  ")
    else print("* ")
  }
  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.