Java Program to Count the Vowels

Get a String and count the number of vowels occurred in string.

Sample Input 1:

Hello

Sample Output 1:

2

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

public class Hello { public static void main(String args[]) { //Write your code here } }

Program or Solution

				
			
					
import java.util.*;

class Program
{
  public static void main(String args[])
  {
     String word;
     int i,count=0;

    Scanner sc=new Scanner(System.in);

    System.out.println("Enter The Word:");
    word=sc.next();

    int len=word.length();
    for(i=0;i<len;i++)
     {
             if(word.charAt(i)=='a' || word.charAt(i)=='e' || word.charAt(i)=='i' || word.charAt(i)=='o' || word.charAt(i)=='u')
                   {
                                   count++;
                   }
      }

    System.out.println("The Occurences Is:"+count);
  }
}
			
				
			

Program Explanation

Comments