Reverse engineering

Report a typo

Write a function called reverseWords that takes a sentence as input and reverses the order of the words using StringBuffer. The function should return the reversed sentence.

If you are up for a challenge, try solving this without using any other built-in string manipulation or reverse methods.

Sample Input 1:

I love kotlin!

Sample Output 1:

kotlin! love I

Sample Input 2:

Welcome to StringBuffer universe

Sample Output 2:

universe StringBuffer to Welcome
Write a program in Kotlin
fun reverseWords(sentence: String): String {
// Write your code here
}

// Don't change the code below
fun main() {
val input = readln()
val reversed = reverseWords(input)
println(reversed)
}

Create a free account to access the full topic