- To print half triangle pattern using alphabet
User Input: 3
Output:
A A B A B C
fun main(args: Array<String>) {
print("Enter number of rows : ")
val userInput = readLine()!!
var rows:Int =userInput.toInt()
var c:Char
for(i in 1..rows) {
c='A'
for(j in 1..i) {
print(c++ +" ")
}
println("")
}
}
Enter number of rows : 4 A A B A B C A B C DProgram
Main logic :
for(i in 1..rows) { //rows : number of rows to print
c='A'
for(j in 1..i) {
print(c++ +" ")
}
println("")
}
You can print the same pattern in small alphabets, just set c='a'
Coming Soon !
QuickThe dreams I chased took me on a journey, a journey more rewarding than the goals