C#C
C#4y ago
Lounder

Simple Recursion [Answered]

How can I make a recursive method return false when one or more of the iterations have returned false but the top recursion has returned true?
-true
  -true
    -false // method should return false


Example with code:
        static void Main(string[] args)
        {
            /*
            8. Write a program in C# Sharp to check whether a given string is Palindrome or not using recursion. Go to the editor
            Test Data :
            Input a string : RADAR
            Expected Output :
            The string is Palindrome.
            */

            Console.WriteLine(ReverseLetters("RADAR"));
        }

        private static bool ReverseLetters(string word)
        {
            if (word.Length > 1 && word[0] == word[word.Length - 1])
            {
                ReverseLetters(word.Substring(1, word.Length - 2));
                return true;
            }

            return false;
        }
Was this page helpful?