Question
Problem Specifications: The Palindrome class Target: This Java program will read in a string from users input, and decide whether this string is a palindrome
Problem Specifications: The Palindrome class Target:
This Java program will read in a string from users input, and decide whether this string is a palindrome or not. The result (whether or not a palindrome) will be printed out onto the screen.
A palindrome is a word, phrase, or sequence that reads the same backward as forward.
For example:
madam
racecar
civic
kayak
Specifications:
In addition to the main method, you need to create another method
isPalindrome()
main Method
a) The main method should create a Scanner object. The main method will use this object to ask the user to input a non-empty string.
b) The main method will then call the isPalindrome method, and pass it the user-entered string as an argument.
c) The main method will then print the returned value from the isPalindrome method onto the screen, telling the user whether the input string is a palindrome or not
isPalindrome Method
a) The isPalindrome method accepts the string argument from the main method and then decides whether this string is a palindrome or not.
b) The isPalindrome method has one return value, which is a boolean value. If the string is a palindrome, return true; if it is not a palindrome, return false.
c) There are many algorithms to decide whether a string is a palindrome or not. Here follows are two of them.
Algorithm:
1) Create a new string that is in a reversed order of the original string. Then decide whether these two strings are equal to each other. If equal, the string is a palindrome; otherwise, not a palindrome.
2) Compare the counter-part characters in the original string. For example, for a palindrome string, its first character should be equal to the last character; the second character should be equal to the second last character, and so on. If any of these counter-part characters are not equal to each other, the string will not be a palindrome.
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