Page 640 - Computer science 868 Class 12
P. 640

8        System.out.println("Enter sentence");
                 9       s=sc.nextLine();

                10       sc=new Scanner(System.in);
                11       System.out.println("Enter word");

                12       w=sc.next();
                13       }

                14
                15       void count()

                16       { StringTokenizer st=new StringTokenizer(s);
                17         String w1;

                18         c=0;
                19         while(st.hasMoreTokens())
                20         { w1=st.nextToken();

                21           if(w.equalsIgnoreCase(w1))

                22             c++;
                23         }
                24        System.out.println("Frequency "+c);

                25       }
                26       public static void main()

                27       { Freq ob=new Freq();
                28         ob.input();

                29         ob.count();
                30              }

                31          }
                32       }


              Output of the preceding program is as follows:
              Enter sentence

              Cat and Dog are playing with another Cat
              Enter word

              Cat
              Frequency 2











                638638  Touchpad Computer Science-XII
   635   636   637   638   639   640   641   642   643   644   645