public boolean isPalindrome(int start, int end) { // Separate case for substrings of length 0 and 1. if (start >= end) return true; // Get first and last characters, converted to lowercase. char first = Character.toLowerCase(text.charAt(start)); char last = Character.toLowerCase(text.charAt(end)); if (Character.isLetter(first) && Character.isLetter(last)) { if (first == last) { // Test substring that doesn’t contain the matching letters. return isPalindrome(start + 1, end - 1); } else return false; } else if (!Character.isLetter(last)) { // Test substring that doesn’t contain the last character. return isPalindrome(start, end - 1); } else { // Test substring that doesn’t contain the first character. return isPalindrome(start + 1, end); } }