Share on Google+Share on Google+

Java count vowels

This program will count the number of vowels in a String.

Java count vowels

In this section you will learn how to count the number of vowels in String. Here you will ask to enter a string of your own choice and then you will get the number of vowels count.

Description of code : In this code first you will ask to enter the string through scanner class and compiler will read the string once you enter the string. Then we have taken a count variable which is initialized to 0. Now we have applied a loop here which will go up to length of string input and inside loop checking each character with if condition for vowel, if it is vowel, count is incremented, prints the no of vowel. to console.

Example  : A Code to count the number of vowel in a string.

import java.util.Scanner;
public class Check {

 public static void main(String args[]) throws NumberFormatException, IOException
    System.out.println("Enter the character");
    Scanner sc = new Scanner(;
    String input = sc.nextLine();
    int count=0;
    System.out.print("Vowel are = ");
         for(int i=0;i<input.length();i++)
            char ch=input.charAt(i);

Output : After executing the program

Download SourceCode


Posted on: June 8, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Java count vowels  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image