/*
Online Java - IDE, Code Editor, Compiler
Online Java is a quick and easy tool that helps you to build, compile, test your programs
online.
*/
public class Main
{
    public static void main(String[] args) 
    {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        // the example is failing on teh first test such as aka? or ?aka
        //System.out.println(isPalindrome("a#kab?"));
        //String sample = "Maneuquenam";
        String sample = "Eva, *&can I see bees in a#* cave?";
        //String sample = "Eva, can I see bees in a cave?";
        //String sample = "#le?$vel";
        //String sample = "This phrase, surely, is not a palindrome!";
        //String sample ="a";
        System.out.println("INITIAL STRING: " + sample);
        String sampleLowerCase = sample.toLowerCase();
        
        System.out.println(isPalindrome(sampleLowerCase));
    }
    public static String isPalindrome(String str)
    {
        boolean specialCharFront=false;
        boolean specialCharBack=false;
        
        Character [] special = new Character[] {' ', ',', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_',
                                                '=', '+', '|', '[', ']', '{', '}', ';', ':', '/', '?', '.', '>'};
        
        while (str.length()>1)
        {
            for (int j=0; j<special.length; j++)
            {
                if (str.charAt(0)==special[j])
                {
                    specialCharFront=true;
                    System.out.println("special char front");
                    System.out.println("analysis on here:" + str.substring(1,( str.length())));
                }
                
                if (str.charAt(str.length()-1)==special[j])
                {
                    specialCharBack=true;
                    System.out.println("special char end");
                    System.out.println("analysis on here:" + str.substring(0,( str.length()-1)));
                }
            }
            
            if(specialCharFront && specialCharBack)
            {
                return isPalindrome(str.substring(1,( str.length()-1)));
            }
            
            if(!specialCharFront && specialCharBack)
            {
                return isPalindrome(str.substring(0,( str.length()-1)));
            }
            
            if(specialCharFront && !specialCharBack)
            {
                System.out.println("string at this point:" + str.substring(1,( str.length())));
                return isPalindrome(str.substring(1,( str.length())));
            }
            
            if (str.charAt(0)==str.charAt((str.length()-1)))
            {
                System.out.println("compare1:" + str.charAt(0));
                System.out.println("compare2:" + str.charAt(str.length()-1));

                System.out.println("analysis on here:" + str.substring(1,( str.length()-1)));
                
                return isPalindrome(str.substring(1,( str.length()-1)));
            }
            else
            {
                System.out.println(str.charAt(0) + " does not equal: " + str.charAt(str.length()-1));
                return "\nfalse";
            }
        }
        return "\ntrue";
    }
}