Page 613 - ComputerScience_Class_11
P. 613

Program 24    Write a program to convert each word of a sentence into a palindrome. The class description
                                 is given below.
                                 Class name                        :   Palindrome
                                 Data Members
                                 String sen                        :   stores the sentence taken from the user
                                 String nwsen                      :    stores the new sentence  after  converting it  to
                                                                     palindromic format
                                 Member Functions
                                 Palindrome()                      :   Constructor to initialize data members.
                                 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;




                                                                                                Internal Assessment  611
   608   609   610   611   612   613   614   615   616   617   618