Page 497 - computer science (868) class 11
P. 497
Program 23 Write a program to convert each word of sentence into palindrome. The class description is
given below.
Class name : convert_to_Palindrome
Data Members
String sen : stores the sentence taken from user
String nwsen : stores the new sentence after converting it to
palindromeic format
Member Functions
convert_to_Palindrome : parameterised constructor
void input() : to input a sentence
void convert() : to convert each word into its palindromic format and
create a new sentence
void display() : to display both the sentences
1 import java.util.*;
2 class Palindrome
3 {
4 String sen,nwsen;
5 Palindrome()
6 {
7 sen="";
8 nwsen="";
9 }
10
11 void input()
12 {
13 Scanner sc=new Scanner(System.in);
14 System.out.println("Enter sentence");
15 sen=sc.nextLine();
16 }
17
18 void convert()
19 {
20 StringTokenizer st=new StringTokenizer(sen);
21 String wd,nw;
22 int len,i;
23 char ch;
24 while(st.hasMoreTokens())
495
Internal Assessment 495

