Loading...
Loading...
A word-games app checks whether a sentence reads the same backwards. Only letters and digits count; spaces, punctuation and upper or lower case are ignored.
Write a utility class StringAnalyzer with a private constructor, a static method String clean(String s) that keeps only lowercase letters and digits, and a static method boolean isPalindrome(String s) that uses clean.
YES, NO, or NOTHING TO CHECK when the line has no letters or digits.Example
Input
3 A man, a plan, a canal: Panama Java rocks Never odd or even.
Output
YES NO YES
Ignoring commas, spaces and case, the first and third read the same both ways.
Try the problem first. Open one hint at a time.
Character.isLetterOrDigit(ch) tells you which characters to keep.
Build the cleaned text with a StringBuilder, then compare characters from both ends moving inwards.
Read the count with nextLine() too, so the sentences are read whole.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor