Page 250 - computer science (868) class 11
P. 250

if(wd.equalsIgnoreCase(revwd))
                            {
                                System.out.println(wd + " is a palindrome");
                            }
                            else
                            {
                                System.out.println(wd+ " is not a palindrome");
                            }
                        }
                        public static void main()
                        {
                            palindrome ob= new palindrome();
                            ob.input();
                            ob.display();
                        }
                    }
                  4.  Design a class to convert and print the given word in alphabetical order.
                     Class name              :   convert
                     Data Members
                     String word             :   To input the word to be converted
                     String sortwd           :   To store the converted word
                     Member Methods
                     convert()               :   Default constructor to initialise the word and sorted
                     void input()            :   To input the word
                     void sort()             :   To sort the word in alphabetical order
                     void display()          :   To print both words
                Ans.  import java.util.*;
                    class convert
                    {
                        String word,sortwd;
                        convert()
                        {
                            word=" ";
                            sortwd=" ";
                        }

                        void input()
                        {
                            Scanner sc= new Scanner(System.in);
                            System.out.print("Enter a word: ");
                            word=sc.next();
                        }

                        void sortword()
                        {
                            int i, j;
                            char ch;
                            for(i='A'; i<='Z'; i++)
                            {
                                for(j=0; j<word.length(); j++)
                                {
                                    ch=word.charAt(j);
                                    if(ch==(char)(i) || ch==(char)(i+32))
                                    {
                                        sortwd=sortwd+ch;
                                    }
                                }

                248248  Touchpad Computer Science-XI
   245   246   247   248   249   250   251   252   253   254   255