5.36 - Palindrome, iterative

Objetive
Create an iterative function to say whether a string is symmetric (a palindrome). For example, "RADAR" is a palindrome.

Resolution
using System;

public class F_Palindrome
{
    public static bool IsPalindrome(string text)
    {
        text = text.ToUpper();
        
  int begin=0;
        int end = text.Length-1;
        
        for(begin = 0; begin < end; begin++)
        {
            if( text[begin] != text[end] )
                return false;
            end--;
        }
  
        return true;
    }   
    
    
    
    public static void Main()
    {
        Console.WriteLine(IsPalindrome("radar"));
        Console.WriteLine(IsPalindrome("ratas"));
    }
}

Popular Posts