Scala

Reversal of string in Scala using recursive function

Reversal of String in Scala using recursive function –


object reverseString extends App {

val s = “24Tutorials”
print(revs(s))

def revs(s: String): String = {
// if (s.isEmpty) “”
if (s.length == 1)  s
else revs(s.tail) + s.head
//else revs(s.substring(1)) + s.charAt(0)

}

}

}

Output:

slairotuT42

Share This Post

Avatar
An Ambivert, music lover, enthusiast, artist, designer, coder, gamer, content writer. He is Professional Software Developer with hands-on experience in Spark, Kafka, Scala, Python, Hadoop, Hive, Sqoop, Pig, php, html,css. Know more about him at www.saikumar.me

Lost Password

Register