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

25                   System.out.println("Palindrome word "+w); // display
                26               else

                27                   System.out.println("Not palindrome word "+w);
                28           }

                29           public static void main()
                30           {

                31               Palword ob=new Palword();
                32               ob.read();

                33               ob.check();
                34           }

                35       }

              The output of the preceding program is as follows:
              Enter word in uppercase
              MADAM
              Palindrome word MADAM



                Program 5      Define a class called Abword to print any name in abbreviated form. For example, AJAY
                               GOPAL RAMESH KRISHNA will be printed as A.G.R.KRISHNA
                               Class name               :    Abword
                               Data Members
                               String nm                :   To store name

                               String anm               :   To store abbreviated name
                               Member Methods
                               void read()              :   Accepts any name in uppercase
                               String print(String a)   :     Using recursive technique, prints name in abbreviated form
                                                           as shown above and returns the result
                               void show()              :   Calls print(String) and prints it in abbreviated form
                               static void main()       :   Creates object and calls other methods

                 1       import java.util.*;

                 2       class Abword    {
                 3           String nm, anm;
                 4           void read() //accept

                 5           {

                 6               Scanner sc=new Scanner(System.in);
                 7               System.out.println("Enter name in uppercase");
                 8               nm=sc.nextLine();





                390390  Touchpad Computer Science-XI
   387   388   389   390   391   392   393   394   395   396   397