Ask Question
1 July, 03:05

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.

+5
Answers (1)
  1. 1 July, 03:14
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers