V
V
Val_Mi2020-09-30 16:13:01
Arrays
Val_Mi, 2020-09-30 16:13:01

Reverse user entered array in kotlin?

fun main() {
    println("Enter String Arrays Elements:")
    val strArray = arrayOf(readLine())
    println("String Array Elements : ${strArray.contentToString()}")
    val reversedArray = strArray.reversedArray()
    println("Reversed String Array Elements : ${reversedArray.contentToString()}")
}

here's what I wrote, the array does not expand, I need help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2020-09-30
@Val_Mi

readLinereturns a string or null, so strArrayyou end up with an array of one string.
Split the input string on some delimiter:

val strArray = readLine()!!.split(' ').toTypedArray()

D
Dmitry Roo, 2020-09-30
@xez

https://kotlinlang.org/api/latest/jvm/stdlib/kotli...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question