Question
Print frequency of vowels in given word using recursion
ENTER THE WORD
abcdefghijklmno
FREQUENCY OF VOWELS IN abcdefghijklmno IS 4
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class frequencyVowelsInWord
{
char ch=' ';
public int FrequencyOfVowels(String wd,int i,int count)
{
if(i< wd.length())
{
ch=wd.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
count++;
}
return FrequencyOfVowels(wd,i+1,count);
}
else
{
return count;
}
}
public static void main()
{
String wd="";
Scanner sc=new Scanner(System.in);
frequencyVowelsInWord ob1=new frequencyVowelsInWord();
System.out.println("ENTER THE WORD");
wd=sc.next();
wd=wd.toLowerCase();
System.out.print("FREQUENCY OF VOWELS IN "+wd+" IS "+ob1.FrequencyOfVowels(wd,0,0));
}
}