A palindrome is a string that reads the same forwards and backwards, such as \"w
ID: 3630204 • 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
It should look like this:
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.
Explanation / Answer
import java.util*; class test { public static boolean palindrome(String input) { boolean ans= true; for(int i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.