- To print full odd reverse triangle pattern using *
User Input: 3
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..(2*rows-i)) {
if(j>=i && (j+i)%2==0)print("* ")
else print(" ")
}
println("")
}
}
Enter number of rows: 4 * * * * * * * * * *Program
Main Logic :
for(i in 1..rows) { //rows : number of rows to print
for(j in 1..(2*rows-i)) {
if(j>=i && (j+i)%2==0)print("* ")
else print(" ")
}
println("")
}
You can print any thing in this pattern, just replace your value with *