Is Palindrome

image_pdfimage_print

using System;
using System.Text;

public class MainClass {
public static bool IsPalindrome(string s) {
int iLength, iHalfLen;
iLength = s.Length – 1;
iHalfLen = iLength / 2;
for (int i = 0; i <= iHalfLen; i++) { if (s.Substring(i, 1) != s.Substring(iLength - i, 1)) { return false; } } return true; } static void Main(string[] args) { string[] sa = new string[]{"level", "minim", "radar"}; foreach (string v in sa) Console.WriteLine("{0} {1}",v, IsPalindrome(v)); } } [/csharp]

This entry was posted in Data Types. Bookmark the permalink.