Go to Top

Monday 3 October 2011

Utilities 13 : Sentence diagnostics

This program will help you to break a sentence into it's constituent words and find out the number of vowels and consonants in each.

Java Program :

import java.io.*;
class vowels
{
 static void main()throws IOException
 {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     int i,j,b=0,v=0,c=0,space=0;
     char k,d='a';
     String a,s="";
     System.out.print("Enter the sentence : ");
     a=br.readLine();
     System.out.print("\n");
     for(i=0;i<=a.length()-1;i++)
     {
         k=a.charAt(i);
         if(k==' ')
         {
              check(i-1,b,a);
              b=i+1;
            }
         if(k!=' ')
         space=space+1;
        }
        if(space!=a.length())
        check(a.length()-1,b,a);
        if(space==a.length())
        check(a.length()-1,0,a);
        System.out.println("Thank you for using this short program");
        }
        static void check(int z,int y,String x)
        {
            int j,v=0,c=0;
            char d;
            String s="";
            for(j=y;j<=z;j++)
            {
                 d=x.charAt(j);
                 s=s+d;
                 if(d=='a' || d=='A' || d=='e' || d=='E' || d=='i' || d=='I' || d=='o' || d== 'O' || d=='u' || d=='U')
                 v=v+1;
                 else
                 c=c+1;
              }
              System.out.println(s+" = No. of vowels = "+v+" & No. of consonants = "+c);
              System.out.print("\n");
    }
}
       
             
             
       
     

No comments:

Post a Comment

ShareThis