import java.util.Scanner; public class Palindrome { public static void main (Str
ID: 3631660 • Letter: I
Question
import java.util.Scanner;
public class Palindrome
{
public static void main (String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a word: ");
String s = in.nextLine();
s = s.replaceAll("\W","");
s = s.toLowerCase();
if(PalindromeCalculator(s))
System.out.println(s + " is a Palindrome.");
else
System.out.println(s + " is not a Palindrome.");
}
public static boolean PalindromeCalculator(String s)
{
if (s.length() <= 1)
return true; // Base case
else
{
if (s.charAt(0) == s.charAt(s.length() - 1))
return PalindromeCalculator(s.substring(1, s.length() - 1 ) );
else
return false;
}//end PalindromeCalculator method
}//end main
}//end class
I need some one to explain this code and the math behind it. Adding comments to each section would be ideal. Thanks yo.