Ask Question
23 December, 20:55

Create a recursive method, a method that calls itself, that returns true or false depending on whether or not a given string is a palindrome. A palindrome is a word that reads the same forwards and backwards, such as "tacocat". Task 2 - The Driver Now we just need to call our method from our Main method and test it with a few different inputs (they may be hardcoded or from user input). Print out the results of each of the method calls along with the string that it was searching through. ∃ Some Sample Output: Received "tacocat" which is indeed a palindrome. Received "lol" which is indeed a palindrome. Received "" which is indeed a palindrome. Received "catermelon" which is not a palindrome.

+2
Answers (1)
  1. 24 December, 00:13
    0
    public class CheckPalindrome{

    public static boolean IsPalindrome (String str) {

    if (str. Length<1)

    {

    return true;

    }

    else

    {

    if (str[0]!=str[str. length-1])

    return false;

    else

    return IsPalindrome (str. substring (1, str. Length-2));

    }

    }

    public static void main (string args[])

    {

    //console. write ("checking palindromes");

    string input;

    boolean flag;

    input=Console. ReadLine ();

    flag = IsPalindrome (input);

    if (flag)

    {

    Console. WriteLine ("Received"+input+"is indeed palindrome");

    }

    else

    {

    Console. WriteLine ("received"+input+"is not a palindrome");

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Create a recursive method, a method that calls itself, that returns true or false depending on whether or not a given string is a ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers