Kotlin Program:

- To print sideway 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=1
  for(i in 1..trows) {
    for(j in 1..k) {
      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=1  // Used to trigger decreasing order of *
for(i in 1..trows) {
  for(j in 1..k) {
    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

The best preparation for good work tomorrow is to do good work today.