Vowel Counter Program In Java - Java Program Example

Here we can see a java program to calculate vowel from sentence and word. When we compile this program then compiler take a sentence or word as input and show output after count each vowel alphabet.

Program Code

package com.androidpro.in;



import
java.util.Scanner;
import
java.util.StringTokenizer;

public class
Main {

   
public static void main(String[] args) {
        System.
out.println(
               
" \t\t\t Vowel Counter \n");
       
System.out.println("Enter A Sentence ");
       
Scanner in = new Scanner(System.in);
       
// Enter a String :
       
String str=in.nextLine().toLowerCase();
       
System.out.print(
               
"\nNumber of Vowels :\n "
                        
+countVowels(str) + "\n");
   
}
   
public static int countVowels(String str) {
       
int count = 0;
        int
len = str.length();
        for
(int i=0; i<len; i++) {
           
char ch = str.charAt(i);
            if
(ch == 'a' ||
                    ch ==
'e' ||
                    ch ==
'i' ||
                    ch ==
'o' ||
                    ch ==
'u') {
                count++
;
           
}
        }
       
return count;
   
}


}



Output

    Vowel Counter

 

Enter A Sentence

Java is a most popular programming language

 

Number of Vowels :

 15

 

Process finished with exit code 0