Created
May 28, 2015 06:04
-
-
Save jongha/50c3bb4b727f4b8ca7db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Palindrome { | |
public static void main(String[] args) { | |
System.out.println(isPalindrome("amor roma")); | |
System.out.println(isPalindrome("Was it a car or a cat I saw?")); | |
} | |
public static Boolean isPalindrome(String text) { | |
StringBuilder builder = new StringBuilder(); | |
for (char c : text.toCharArray()) { | |
if (Character.isAlphabetic(c)) { | |
builder.append(Character.toLowerCase(c)); | |
} | |
} | |
text = builder.toString(); | |
int len = text.length(); | |
for (int i = 0; i < len / 2; ++i) { | |
if (text.charAt(i) != text.charAt(len - i - 1)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment