Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Java String-examples Java count vowels

Related Tutorials


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


If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  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.

Posted on: June 8, 2013

Related Tutorials

Discuss: Java count vowels  

Post your Comment

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