Home > Software engineering >  Kotlin: I in range
Kotlin: I in range

Time:08-04

val x= readLine()!!.toInt()
for (i in 1..x) {
    repeat(x) { print("#") }
    println()
}

I am trying to create a program in which the user inputs a number and the output is that number in hashtags, eg, input 3, output # ## ###, however, right now, if i input 3, the output is ###,###,###

CodePudding user response:

inside repeat use i instead of x.

fun main() {
    val x= 3
    for (i in 1..x) {
        repeat(i) { print("#") }
        println()
    }
}
  • Related