Programming Course in C# ¡Free!

Palindrome, iterative

 Saturday, April 06, 2013 published by Exercises C#
Proposed exercise

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

Output



Solution


using System;
public class F_Palindrome
{
public static bool IsPalindrome(string text)
{
text = text.ToUpper();

int j = text.Length - 1;

for(i = 0; i < j; i++)
{
if( text[i] != text[j] )
return false;
j--;
}

return true;
}   

public static void Main()
{
Console.WriteLine(IsPalindrome("radar"));
Console.WriteLine(IsPalindrome("ratas"));
}
}