Page 475 - CA_Blue( J )_Class10
P. 475

Variable Description
                    NAME        DATATYPE                                    DESCRIPTION
                  str          String        Accept sentence to be checked
                  word         String        Word extracted

                  wordrev      String        Word extracted in reverse order
                  ch           char          Character extracted from sentence
                  i            int           Loop Variable

                  len          int           Length of the sentence


                               Write a program to input a word and convert it to its piglatin format.
                  Program 15   Sample input          : Print
                               Sample output         : INTPRAY


                   1      import java.util.*;           //importing package "util"

                   2      class piglatinword           //declaration of class
                   3      {

                   4          public static void main()
                   5          {

                   6              Scanner sc = new Scanner(System.in);
                   7              String word="", wordpig="";       //declaration of variable

                   8              int len,i,j=0;
                   9              char ch;

                  10              System.out.print("Enter a word : ");
                  11              word = sc.next ();                    //Enter of word
                  12              word=word.toUpperCase();

                  13              len = word.length();                    //Length of word

                  14              for (i = 0; i < len; i++)
                  15              {
                  16                  ch = word.charAt(i);                    //Extraction of character

                  17                  if (ch == 'A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')    //
                              checking for vowels
                  18                  {

                  19                      j=i;
                  20                      break;

                  21                  }
                  22              }

                  23              wordpig=word.substring(j)+word.substring(0,j)+"AY";     // Piglatin
                              Format



                                                                                                                       473
                                                                                                   Internal Assessment  473
   470   471   472   473   474   475   476   477   478   479   480