July 05, 2013

Java program to find the numbers a vowels in a string

Write a program in Java to find the numbers a vowels in a string.


VOWELS

import java.io.*;
class vowels
{
public static void main(String args[])
{
try
{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the string:");
String text=bf.readLine();
int vowel=0;
for(int i=0;i<text.length();i++)
{
char c=text.charAt(i);
if(c=='A'||c=='a'||c=='E'|| c=='e'||c=='I'|| c=='i'||c=='O'|| c=='o'||c=='U'||c=='u')
{
vowel++;
}
}
System.out.println("There are "+vowel+" vowels in the string" );
}
catch(Exception e){}
}
}



OUTPUT

C:\Program Files\Java\jdk1.5.0\bin>java vowels

Enter the string:
tatya
There are 1 vowels in the string

No comments:
Write comments