Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a method isPalindrome() that takes a String and returns whether it is a palindrome or not. Write a method longest_palin() that takes a string

Write a method isPalindrome() that takes a String and returns whether it is a palindrome or not.

Write a method longest_palin() that takes a string and returns the longest substring in it that is a palindrome. A brute force method of finding the longest palindromic substring is to loop over all possible substrings and keep track of the longest one encountered. To loop over all substrings, you may use a nested loop with an outer counter i (0 ≤ i < n) and an inner counter j (i < j < n) to generate the substrings st[i:j+1]. Use the isPalindrome() method you wrote.

In the main method, ask the user to enter any sentence. Your program should then display the longest substring in the entered text. Note that all spaces and the case of the letters should be ignored.

Step by Step Solution

3.50 Rating (157 Votes )

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_2

Step: 3

blur-text-image_3

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

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Algorithms questions

Question

19. How does L-dopa relieve the symptoms of Parkinsons disease?

Answered: 1 week ago