Code Below:


import java.util.*;
class prg
{
    public static void main()
    {
        Scanner s=new Scanner(System.in);
        int i,l,c=0;
        String w="",rev="";
        System.out.println("Enter a sentence");
        String st=s.nextLine();
        st=st+" ";
        st=st.toUpperCase();
        l=st.length();
        for(i=0;i< l;i++)
        {
            char ch=st.charAt(i);
            if(ch!=' ')
            {
                w=w+ch;
                rev=ch+rev;
            }
            else
            {
                System.out.print(rev+" ");
                if(rev.equals(w))
                c++;
                w="";
                rev="";
            }
        }
        System.out.println();
        System.out.println("No. of palindrome words="+c);
    }
}