Reverse, recursive Learn programming Visual Basic (VB.net)

Lesson:

Functions


Exercise:

Reverse, recursive


Objetive:

Create a program that uses recursion to reverse a string of characters (for example, from "Hello" it would return "olleH").


Code:

Imports System
Public Class exercise128
    Public Shared Function Reverse(ByVal text As String) As String
        If text.Length <= 1 Then Return text
        Dim firstLetter As Char = text(0)
        Dim rest As String = text.Substring(1)
        Return Reverse(rest) & firstLetter
    End Function

    Public Shared Sub Main(ByVal args As String())
        Console.WriteLine(Reverse("Juan"))
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.