Question

Print frequency of Consonants in given word using recursion.

				
					ENTER THE WORD
abcdefghijklmno
FREQUENCY OF CONSONANTS  IN abcdefghijklmno 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 frequencyConsonantsInWord
{
    char ch=' ';
    public int FrequencyOfConsonants(String wd,int i,int count)
    {

        if(i< wd.length())
        {
            ch=wd.charAt(i);
            if(Character.isLetter(ch)==true)
            {
                if(ch!='a'&& ch!='e'&& ch!='i'&& ch!='o'&& ch!='u')
                {
                    count++;
                }

            }

            return FrequencyOfConsonants(wd,i+1,count);
        }
        else
        {
            return count;  
        }
    }

    public static void main()
    {
        String word="";
        Scanner sc=new Scanner(System.in);
        frequencyConsonantsInWord ob1=new frequencyConsonantsInWord();
        System.out.println("ENTER THE WORD");
        word=sc.next();
        word=word.toLowerCase();
        System.out.print("FREQUENCY OF CONSONANTS IN "+word+" IS "+ob1.FrequencyOfConsonants(word,0,0));

    }

}


				
			

Coding Store

Leave a Reply

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