Page 639 - Computer science 868 Class 12
P. 639
19 { w1=st.nextToken();
20 w="";l=w1.length();
21 for(int i=0;i<l;i++)
22 { char ch=w1.charAt(i);
23 w=ch+w;
24 }
25 ps=ps+(w1+w)+" ";
26
27 }
28 System.out.println("New sentence "+ps);
29 }
30
31 public static void main()
32 { Palindrome ob=new Palindrome();
33 ob.input();
34 ob.convert();
35 }
36 }
37 }
Output of the preceding program is as follows:
Enter sentence
Rahul is a boy
New sentence RahulluhaR issi aa boyyob
Program 26 Calculate Frequency of a given word using String Tokenizer
A sentence is accepted from the user along with a word. Find out its frequency in the given
sentence using string tokenizer. Also print the total number of tokens.
1 class Freq
2 { String s,w;
3 int c;
4 Freq()
5 { s="";c=0;}
6 void input()
7 { Scanner sc=new Scanner(System.in);
637
Internal Assessment 637

