- To print half triangle pattern using number
User Input: 3
Output:
1 2 2 3 3 3
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(i+" ")
}
println("")
}
}
Enter number of rows : 4 1 2 2 3 3 3 4 4 4 4Program
Main logic :
for(i in 1..rows) { //rows : number of rows to print
for(j in 1..i) {
print(i +" ")
}
println("")
}
Concept
Coming Soon !
QuickStrength does not come from winning. Your struggles develop your strengths.