Answer the question
In order to leave comments, you need to log in
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()}")
}
Answer the question
In order to leave comments, you need to log in
readLine
returns a string or null, so strArray
you end up with an array of one string.
Split the input string on some delimiter:
val strArray = readLine()!!.split(' ').toTypedArray()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question