Question

Print frequency of vowels in given sentence using recursion

				
					ENTER THE SENTENCE
quick brown fox jumped over the lazy dog
FREQUENCY OF VOWELS IN quick brown fox jumped over the lazy dog IS 11
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class frequencyVowelsInSentence
{
    char ch=' ';
    public int FrequencyOfVowels(String sen,int i,int count)
    {

        if(i< sen.length())
        {
            ch=sen.charAt(i);
            if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
            {
                count++;

            }
            return FrequencyOfVowels(sen,i+1,count);
        }
        else
        {
            return count;  
        }
    }

    public static void main()
    {
        String sen="";
        Scanner sc=new Scanner(System.in);
        frequencyVowelsInSentence ob1=new frequencyVowelsInSentence();
        System.out.println("ENTER THE SENTENCE");
        sen=sc.nextLine();
        sen=sen.toLowerCase();
        System.out.print("FREQUENCY OF VOWELS IN "+sen+" IS "+ob1.FrequencyOfVowels(sen,0,0));

    }

}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *