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