Exercise
Function Palindrome, recursive
Objetive
Write a Visual Basic (VB.Net) recursive function to say whether a string is symmetric (a palindrome). For example, "RADAR" is a palindrome.
Code
Imports System
Public Class exercise131
Public Shared Function IsPalindrome(ByVal text As String) As Boolean
If text.Length <= 1 Then
Return True
Else
If text(0) <> text(text.Length - 1) Then
Return False
Else
Return IsPalindrome(text.Substring(1, text.Length - 2))
End If
End If
End Function
Public Shared Sub Main()
Console.WriteLine(IsPalindrome("radar"))
Console.WriteLine(IsPalindrome("pato"))
End Sub
End Class