Question
Write a java program that reads a string, and then prints a message saying whether it is a palindrome in two different ways [recursively and
Write a java program that reads a string, and then prints a message saying whether it is a palindrome in two different ways [recursively and non-recursively]. A palindrome is a string that is the same forward and backward. For example, [Mom] is a Palindrome.
In reclusive way, the main method should read the string and call a recursive (static) method palindrome that takes a string and returns true if the string is a palindrome, false otherwise. It is easy to define a palindrome recursively as follows:
A string containing fewer than 2 letters is always a palindrome.
A string containing 2 or more letters is a palindrome if :
o Its first and last letters are the same, and
o The rest of the string (without the first and last letters) is also a palindrome.
s.length() returns the number of characters in s. For example: if s="happy" Then: s.length = 5
s.charAt(i) returns the ith character of s, 0-based. For example: if s="happy" Then: s.charAt(1) equals 'a'
Procedure
Step 1: Start the process.
Step 2: Import the Scanner class from util package.
Step 3: Create a class to hold your main function; only alphabetical characters will be checked (no difference between uppercase / lowercase characters)
Step 4: Implement the non-recursive Palindrome.
Step 5: Implement the recursive Palindrome.
Step 6: Call the function isPalendrome() to Check if the text is a Palindrome.
Step 7: Print the two results.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started