I need to check a palindrome in a separate class but ignore non alphabet characters. So for example, radar would still qualify if it was written r,a,d,a,r
I believe I could use regex, but I don't know how.
Here is what I have so far,
public static boolean isNonAlpha(char c) {
return (c == '-' || c == '.' || c == ' ' || c == ')' || c == '(') || c == '<' || c == '>' || c == ',';
}
public static String checkInput(String test){
int startChar = 0;
int endChar = test.length() - 1;
while (startChar < endChar) {
if (test.charAt(startChar) != test.charAt(endChar)) {
System.out.println("Your word is not a palindrome.");
System.exit(0);
} else {
if (test.charAt(startChar) == test.charAt(endChar))
startChar++;
endChar--;
}
}
System.out.println("Your word is indeed a palindrome.");
return test;
}
I'm stuck on how to incorporate my isNonAlpha method, or how to use regex