Beginner CS student here. I'm working on a Palindrome checker for a class and this is entirely functional if not for the required Uppercasing in the main method. How could I made my isPalindromeRecursive method ignore the string case?
I need to figure out how to make a case-insensitive method. Also I have to have both a isPalindromeRecursive and isPalindromeIterative method and I don't understand the difference if someone could explain.
public class PalindromeDetector {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int count = 2;
for(int i = 0; i < count; i++ ) {
System.out.println("Enter a name.");
String name = keyboard.nextLine();
// I wanted to experiment with the new String tools we learned so my capitalization is strange.
String cap = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
System.out.println(cap);
if(isPalindromeRecursive(cap))
System.out.println(cap + " is a palindrome.");
else
System.out.println(cap + " is not a palindrome.");
count++;
}
}
public static boolean isPalindromeRecursive(String s) {
if(s.length()==0 || s.length() ==1) {
return true;
}
if(s.charAt(0) == s.charAt(s.length()-1)) {
return isPalindromeRecursive(s.substring(1, s.length()-1));
}
return false;
}
}