192k views
4 votes
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.

User BernardoGO
by
5.2k points

1 Answer

4 votes

Answer:

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");

}

}

Step-by-step explanation:

User Thegaw
by
5.7k points