Java Program code to count vowels in given word

The program counts the number of vowels in the given word
Complied using JDK and Netbeans IDE


Code:



                                                                     
                                                                     
                                                                     
                                             
package vowels;

import java.io.*;
 public class vowels  {
        public static void main(String[] args)throws IOException {
        BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the string ");
        String s=stdin.readLine();
        int count=0;
        for(int i=0;i<s.length();i++)
        {
           char c=s.charAt(i);
          if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u'||c=='A' || c=='E' || c=='I' || c=='O' || c=='U')
           {
              count=count+1;
           }
        }
        System.out.println("vowels= "+count);
        
    }

}








Output:

                                                                     
                                                                     
                                             
 Enter the string 
 Roger
 vowels= 2


3 comments:

Unknown said...

Awsome....

Unknown said...
This comment has been removed by the author.
Unknown said...

Great Stuff... I Am New In Java.. An Enjoying It..
I Am Also Writing For Java Beginners..
Objects In Java

Post a Comment

If You Are Asking Some Question On This Comment Then Click On Subscribe by email Link