Question
Write a program to read several lines from a file called H.in. For each line, check whether it is a palindrome. For each line read
Write a program to read several lines from a file called H.in. For each line, check whether it is a palindrome. For each line read from the file, print only the lines that are palindromes. Recall that a palindrome is a string that is the same backwards and forwards, ignoring spaces and punctuation. Some example palindromes are radar and I, Madam, I made radio. So I dared! Am I mad? Am I?? You may use theremoveWS method from Lab. Your palindrome checking method must be recursive. In JAVA:
removeWS :
public static String removeWS(String a) { if (a.length() == 0) return a; String b = Character.isLetterOrDigit(a.substring(0, 1).charAt(0)) ? a.substring(0, 1) : ""; return b + removeWS(a.substring(1)); } }
H.in:
You must be the change you want to see in the world Sore was I, ere I saw Eros. A man, a plan, a canal -- Panama Never a foot too far, even. BORROW - OR ROB? Euston SaW I was not Sue. THIS IS JUST A TEST. "Stop!" nine myriad murmur. "Put up rum, rum, dairymen, in pots." Live on evasions?! No, I save no evil. Red Roses run no risk, sir, on nurses order. The best way out is always through........
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