Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Sub Main()
- Dim input As String = "hello"
- Dim reversed As String = ReverseString(input)
- Console.WriteLine("Reversed string: " & reversed)
- End Sub
- Function ReverseString(input As String) As String
- ' Base case: if the string is empty or has one character, return it as is
- If input.Length <= 1 Then
- Return input
- Else
- ' Recursive case: take the last character and append the reversed rest of the string
- Return input(input.Length - 1) & ReverseString(input.Substring(0, input.Length - 1))
- End If
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment