Page 377 - Computer science 868 Class 12
P. 377

52          public static void main(String args[])
                   53          {

                   54              Scanner sc=new Scanner(System.in);
                   55              System.out.print("Enter the string:");
                   56              String s=sc.nextLine();

                   57              TheString obj=new TheString(s);

                   58              obj.countFreq();
                   59              obj.display();
                   60          }

                   61      }


                 The output of the preceding program is as follows:
                 Enter the string:India is a great country
                 Original String :India is a great country
                 Number of words: 5
                 Number of consonants: 11


                   Program 9     A class Rearrange has been defined to modify a word by bringing all the vowels in the word
                                 at the beginning followed by the consonants.
                                 Example: ORIGINAL becomes OIIARGNL
                                 Some of the members of the class are given below.
                                 Class name                     :   Rearrange
                                 Data Members/Instance variables
                                 wrd                            :   to store a word
                                 newwrd                         :   to store the rearranged word
                                 Member Functions/Methods
                                 Rearrange()                    :   default constructor
                                 void readword()                :   to accept the word in
                                 uppercase vow freq_vow_con()  :    to find the frequency of vowels and consonants in the
                                                                   word and display them with an appropriate message
                                 void arrange()                 :    to rearrange the word by bringing the vowels at the
                                                                   beginning followed by consonants
                                 void display()                 :    to display the original word along with the rearranged
                                                                   word
                                 Specify  the class  Rearrange giving  the details  of the  constructor(),  void  readword(),
                                 void freq _vow_con(), void arrange() and void display(). Define the main() function to create
                                 an object and call the functions accordingly to enable the task.           [ISC 2019]

                   1       import java.util.*;

                   2       class Rearrange
                   3       {




                                                                                                                       375
                                                                                                              Strings  375
   372   373   374   375   376   377   378   379   380   381   382