- To print X pattern using *
User Input: 3
Output:
* * * * *
fun main(args: Array<String>) {
print("Enter number of rows : ")
val userInput = readLine()!!
var rows:Int =userInput.toInt()
for(i in 0..rows-1) {
for(j in 0..rows-1) {
if(i==j||j==(rows-i-1))print("* ")
else print(" ")
}
println("")
}
}
Enter number of rows: 4 * * * * * * * *Program
Main Logic :
for(i in 0..rows-1) { //rows : number of rows to print
for(j in 0..rows-1) {
if(i==j||j==(rows-i-1))print("* ")
else 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.