- To print half 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 1..rows) {
for(j in 1..i) {
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..i) {
print("* ")
}
println("")
}
You can print any thing in this pattern, just replace your value with *
Coming Soon !
QuickIn order to succeed you must fail, so that you know what not to do the next time.