Reverse words in a string: Difference between revisions

Added Kotlin
(Omitted to add code and output)
(Added Kotlin)
Line 1,545:
----------------------- Robert Frost</pre>
 
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
 
fun reversedWords(s: String) = s.split(" ").reversed().joinToString(" ")
 
fun main(args: Array<String>) {
val s = "Hey you, Bub!"
println(reversedWords(s))
println()
val sl = listOf(
" ---------- Ice and Fire ------------ ",
" ",
" fire, in end will world the say Some ",
" ice. in say Some ",
" desire of tasted I've what From ",
" fire. favor who those with hold I ",
" ",
" ... elided paragraph last ... ",
" ",
" Frost Robert ----------------------- "
)
sl.forEach { println(reversedWords(it).trimStart()) }
}</lang>
 
{{out}}
<pre>
Bub! you, Hey
 
------------ Fire and Ice ----------
 
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
 
... last paragraph elided ...
 
----------------------- Robert Frost
</pre>
 
=={{header|Liberty BASIC}}==
9,490

edits