Write a kotlin program to reverse a string using the recursive method

var reverse = ""

fun reverseString(str: String): String {

    if(str.length == 1) {
        return str
    } else {
        reverse += str[str.length - 1] + reverseString(str.substring(0, str.length - 1))
        return reverse
    }
}

fun main(args: Array<String>) {
    var str = "cherchertech"
    println("Original string : "+str)
    println("Reversed string : " + reverseString(str))
}

Output

Original string : cherchertech
Reversed string : hcetrehcrehc
About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions