BAEL-1525: Article code completed.
This commit is contained in:
14
core-java/src/main/java/com/baeldung/string/Palindrome.java
Normal file
14
core-java/src/main/java/com/baeldung/string/Palindrome.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.string;
|
||||
|
||||
public class Palindrome {
|
||||
|
||||
public boolean isPalindrome(String text) {
|
||||
text = text.replaceAll("\\s+", "").toLowerCase();
|
||||
int length = text.length();
|
||||
int forward = 0;
|
||||
int backward = length - 1;
|
||||
boolean palindrome = true;
|
||||
while ((backward > forward)?(palindrome=(text.charAt(forward++) == text.charAt(backward--))):false);
|
||||
return palindrome;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user