
/*
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#ka?"));
        
        System.out.println(isPalindrome("Eva, can I see bees in a cave?"));
        
        
    }
    
    public static String isPalindrome(String str)
    {
        
        boolean specialCharFront=false;
        boolean specialCharBack=false;
        
        //Special characters need to be excluded from checking....
        //'\'   unable to process these in special characters since it recognises it as \
        
        Character [] special = new Character[] {',', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '|', '[', ']', '{', '}', ';', ':', '/', '?', '.', '>'};
        
        // this will force the string to get shorter
        
        while (str.length()>1)
        {
            
            for (int j=0; j<special.length; j++)
            {
                if (str.charAt(0)==special[j])
                {
                    specialCharFront=true;
                     //return isPalindrome(str.substring(1,( str.length()-1)));
                }
                
                 if (str.charAt(str.length()-1)==special[j])
                {
                    specialCharBack=true;
                     //return isPalindrome(str.substring(1,( str.length()-1)));
                }
            }
            
            if(specialCharFront && specialCharBack)  // if special character in both front and back, it shortens string
            // by 1 front and back
            {
                System.out.println("1");
                return isPalindrome(str.substring(1,( str.length()-1)));
                
            }
            
             if(!specialCharFront &&  specialCharBack)  //if special character front 
            {
                System.out.println("2");
                
                return isPalindrome(str.substring(0,( str.length()-1)));
               
            }
            
             if(specialCharFront &&  !specialCharBack)  //if special character front 
            {
                System.out.println("3");
                return isPalindrome(str.substring(1,( str.length()-1)));
                
            }
            
            
        
        // it needs to move the position before first comparison also.....
            
        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));
            
            
            return isPalindrome(str.substring(1,( str.length()-1)));
        }
    
        else
        {
            return "false";
        }
        }
        
        return "true";
        
    }
    
}
            
            