Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A palindrome is a string that is the same forward and backward. In Chapter 3 you saw a program that uses a loop to determine

A palindrome is a string that is the same forward and backward. In Chapter 3 you saw a program that uses a loop to determine whether a string is a palindrome. However, it is also 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 its first and last letters are the same, and the rest of the string (without the first and last letters) is also a palindrome. Write a program that prompts for and reads in a string, then prints a message saying whether it is a palindrome. Your 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. Recall that for a String s in Java, s.length() returns the number of charaters in s s.charAt(i) returns the ith character of s, 0-based s.substring(i,j) returns the substring that starts with the ith character of s and ends with the j-1st character of s (not the jth!), both 0-based. So if s="happy", s.length=5, s.charAt(1)=a, and s.substring(2,4) = "pp". this was all I was given to work with, please do not use anything past a beginners level of computer science so that I am able to understand it we are only on the chapter titled recursion, if you have any questions please ask

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. Describe the strategic training and development process.

Answered: 1 week ago

Question

10. Microsoft Corporation

Answered: 1 week ago