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

9               nm=" "+nm;
                   10              anm="";

                   11          }
                   12          String print(String a)    {

                   13              if(a.equals("")) // end of name
                   14                  return anm;

                   15              else if(a.charAt(0)==' ') // if space
                   16              {

                   17                  anm=anm+a.charAt(1)+"."; // add next character
                   18                  return print(a.substring(1)); // recursive case

                   19              }
                   20              else

                   21              {
                   22                  return print(a.substring(1)); // recursive case

                   23              }
                   24          }

                   25          void show() // display
                   26          {

                   27              int p=nm.lastIndexOf(' '); // last space position
                   28              String s=nm.substring(0,p);
                   29              String r=print(s); // passing name excluding surname

                   30              r=r+nm.substring(p+1);

                   31              System.out.println("Abbreviated name ="+r);
                   32          }
                   33          public static void main()    {

                   34              Abword ob=new Abword();
                   35              ob.read();

                   36              ob.show();
                   37          }

                   38      }

                 The output of the preceding program is as follows:
                 Enter name in uppercase
                 AJAY  GOPAL  RAMESH  KRISHNA
                 Abbreviated name = A.G.R.KRISHNA





                                                                                                                       391
                                                                                                           Recursion   391
   388   389   390   391   392   393   394   395   396   397   398