Array-promo

Question

print frequency of consonants or non-vowels in the given sentence.

Share code with your friends

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

Code

				
					
import java.util.Scanner;
public class printFrequencyOfConsonantsInSentence 
{  
    public static void main(String[] args)
    {  
        String sen="";
        char ch=' ';
        int i=0,len=0,count=0;
        Scanner sc = new Scanner(System.in);    
        
        System.out.println("Enter a sentence");   
        sen = sc.nextLine(); 
        
        sen=sen.toLowerCase();
        len=sen.length();
        for(i=0;i< len;i++)
        {
            ch=sen.charAt(i);
            if(ch!='a'&&ch!='e'&&ch!='i'&&ch!='o'&&ch!='u'&&ch!=' ')
            {
                count++;
            }
        }
        System.out.println("Frequency of Consonants in sentence is:"+count);
    }  
}    
    

				
			

Coding Store

Leave a Reply

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