• + 0 comments

    code in java 15 class solution {

    ArrayDeque ad1=new ArrayDeque(); //for stack ArrayDeque ad2=new ArrayDeque(); //for queue

    void pushCharacter(char ch)
    {
        ad1.push(ch);
    
    }
    void enqueueCharacter(char ch)
    {
        ad2.add(ch);
    }
    
    
    char popCharacter()
    {
        return (char)ad1.pop();
    }
    
    char dequeCharacter()
    {
        return (char)ad2.poll();
    }
    
    
    
    
    
    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        Solution p=new Solution();
        for(int i=0;i<s.length();i++)
        {
            p.pushCharacter(s.charAt(i));
            p.enqueueCharacter(s.charAt(i));
        }
    
        boolean b=true;
        for(int i=0;i<s.length()/2;i++)
        {
            if(p.popCharacter()!=p.dequeCharacter())
            {
                b=false;
                break;
            }
        }
        if(b)
        {
            System.out.println("The word, "+s+", is a palindrome.");
        }
        el
                }se
        {
        System.out.println("The word, "+s+", is not a palindrome.");
        }
    }