- To print half opposite reverse triangle pattern using *
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 rows downTo 1) {
for(j in 1..rows) {
if(j<i)print(" ")
else print("* ")
}
println("")
}
}
Enter number of rows : 4 * * * * * * * * * *Program
Main logic :
for(i in rows downTo 1) { //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 *
Coming Soon !
QuickIf your happiness depends on what somebody else does, I guess you do have a problem.