Page 473 - CA_Blue( J )_Class10
P. 473

11              name=sc.nextLine();                //Accepting full name
                  12              name=" "+name;

                  13              space = name.lastIndexOf(‘ ‘);            // Index of last space
                  14              for(i=0;i<space;i++)           // Loop to extract character

                  15              {
                  16                  ch=name.charAt(i);

                  17                  if(ch==’ ‘)
                  18                  {

                  19                      abbname=abbname+name.charAt(i+1)+".";
                  20                  }

                  21              }
                  22              abbname=abbname+name.substring(space+1);

                  23              System.out.println("Abbreviated Name : "+abbname);     //print abbreviated
                              name
                  24          }               //close of main()
                  25      }               //close of class

                 Output

                 Enter full name : Ram Kumar Sharma
                 Abbreviated Name : R.K.Sharma

                                                            Variable Description
                    NAME        DATATYPE                                    DESCRIPTION
                  name         String        Full name of a person
                  abbname      String        Abbreviated name of the person

                  ch           char          Character extracted
                  space        int           Index of last space
                  i            int           Loop variable

                 (c)  Palindrome string, pig Latin, alphabetical order of characters, etc.



                  Program 14 Write a program to input a sentence and print the palindromic words in the sentence.



                   1      import java.util.*;           //importing package "util"
                   2      class palindromicword           //declaration of class

                   3      {
                   4          public static void main()

                   5          {




                                                                                                                       471
                                                                                                   Internal Assessment  471
   468   469   470   471   472   473   474   475   476   477   478