21
Developer's Corner / Re: C# Palindrom Recursive Program
« on: April 19, 2007, 03:43 PM »
This is the Palindrom in non recursive format but I need to put it in recursive format. From my understanding I should put most of this code in a method, probably in another class, then have the main method call upon it every time the system loops
==========================================================
==========================================================
Code: C# [Select]
- namespace RecursivePalindromeTester
- {
- class Palindrome
- {
- String str, another = "y";
- int left, right;
- while (another.ToUpper() == "Y")
- {
- Console.Out.WriteLine("Enter a potential Palindrome:");
- str = Console.In.ReadLine();
- left = 0;
- right = str.Length - 1;
- while (str[left] == str[right] && left < right)
- {
- left++;
- right--;
- }
- Console.Out.WriteLine();
- if (left < right)
- Console.Out.WriteLine("String is Not a Palindrome.");
- else
- Console.Out.WriteLine("String is a Palindrome.");
- Console.Out.WriteLine();
- Console.Out.Write("Test another PalindromTester (Y/N)? ");
- another = Console.In.ReadLine();
- }
- }