Ask 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 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.

+3
Answers (1)
  1. 26 July, 01:49
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers