Page 430 - CA_Blue( J )_Class10
P. 430

21             else

                22             {
                23                 if(wd.equalsIgnoreCase(extwd))

                24                     c++;
                25                 extwd="";

                26             }
                27         }
                28         System.out.println("No. of : " + wd + " : " +c);

                29     }

                30 }

                              To input a sentence and print the palindromic words in the sentence.
                Program 6     Example: Mom and Dad went to market.
                              Output: Mom
                                             Dad

                 1 import java.util.*;
                 2 class palindromic_word

                 3 {
                 4     public static void main()

                 5     {

                 6         Scanner sc= new Scanner(System.in);
                 7         String str, wd="" , revwd="";
                 8         int i, l;

                 9         char ch;

                10         System.out.print("Enter a sentence: ");
                11         str=sc.nextLine();
                12         str= str+ " " ;

                13         l=str.length();
                14         for(i=0;i<l;i++)

                15         {
                16             ch=str.charAt(i);

                17             if(ch!=' ')
                18             {

                19                 wd=wd+ch;
                20                 revwd=ch+revwd;

                21             }


                428428  Touchpad Computer Applications-X
   425   426   427   428   429   430   431   432   433   434   435