- To print full triangle pattern using alphabet
User Input: 3
Output:
A A B A A B C B A
fun main(args: Array<String>) {
print("Enter number of rows : ")
val userInput = readLine()!!
var rows:Int =userInput.toInt()
var c:Char
for(i in rows downTo 1) {
c='A'
for(j in 1..(2*rows-i)) {
if(j<i)print(" ")
else {
if(j<rows)print("${c++} ")
else print("${c--} ")
}
}
println("")
}
}
Enter number of rows: 4 A A B A A B C B A A B C D C B AProgram
Main Logic :
for(i in rows downTo 1) {
c='A'
for(j in 1..(2*rows-i)) {
if(j<i)print(" ")
else {
if(j<rows)print("${c++} ")
else print("${c--} ")
}
}
println("")
}
You can print the same pattern in small alphabets, just set c='a'
Coming Soon !
QuickIn order to succeed you must fail, so that you know what not to do the next time.