Number Of Vowels In A String
Write a program to enter a string and print the number of vowels in it.
/* WAP to enter a string and display the number of vowels in it. */
import java.io.*;
class StringQ02
{
public static void main(String arg[])throws IOException
{
int i, l, vowels;
String str;
char ch;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a string : ");
str=br.readLine();
l = str.length();
// To count no of vowels
vowels = 0;
for(i=0;i < l;i++){
ch = str.charAt(i);
//Count blank spaces
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
vowels++;
}
System.out.println("No of Vowels: "+vowels);
}//end of main
}//end of class
Have something to say? Log in to comment on this post.
0 comments