Count number of vowels in string in java

//Count number of vowels in string in java


import java.util.*;
public class M
{
public static void main(String args[])
{
String str;
int count=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String :");
str=sc.nextLine();
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)=='A'
||str.charAt(i)=='E'||str.charAt(i)=='I'||str.charAt(i)=='O'||str.charAt(i)=='U'
||str.charAt(i)=='a'||str.charAt(i)=='e'||str.charAt(i)=='i'||str.charAt(i)=='o'||str.charAt(i)=='u')
{
count++;
}
}
System.out.println("Total number of Vowels : "+count);
}
}



OUTPUT:
Enter the String :
This is best example for count number of vowels.
Total number of Vowels : 14

No comments:

Post a Comment