A palindrome is a string that reads the same forwards and backwards, such as \"w
ID: 3630200 • Letter: A
Question
A palindrome is a string that reads the same forwards and backwards, such as "warts n straw" or "radar".Write a program that will accept a string of characters terminated by a carriage return and will determine whether or not the string is a palindrome. In your program, define a static method called palindrome that begins as follows:
/*****************************************************************
* Precondition: The String input contains letters and blanks in
* positions input[0] through input[length - 1].
* Returns true if the string is a palindrome and false otherwise.
*****************************************************************/
public static boolean palindrome(String input) {
Hint: Use the methods charAt(int index) and toLowerCase( ) or toUpperCase( ) of the String class.
Note:
Consider uppercase and lowercase versions of the same letter to be equal, so the following will be considered a palindrome by your program:
Able was I ere I saw Elba
Example Output
Input the string that needs to be checked if it is a palindrome
(press n to terminate the program):
Radar
BINGO!! The entered input is a palindrome!
Input the string that needs to be checked if it is a palindrome
(press n to terminate the program):
AaBbAa
BINGO!! The entered input is a palindrome!
Input the string that needs to be checked if it is a palindrome
(press n to terminate the program):
ah ha
BINGO!! The entered input is a palindrome!
Input the string that needs to be checked if it is a palindrome
(press n to terminate the program):
ah ha!
The entered input is NOT a palindrome.
Input the string that needs to be checked if it is a palindrome
(press n to terminate the program):
ah h a
The entered input is NOT a palindrome.
Input the string that needs to be checked if it is a palindrome
(press n to terminate the program):
n
Process Palindrome finished