Ads Top

Program to find count of vowels and consonant

Program to find count of vowels and consonant


import java.util.Scanner;
public class Vowel {
public static void main(String[] args) {
System.out.println("enter a string:");
Scanner sc=new Scanner(System.in);
String v=sc.nextLine();
int len=v.length();
char[] vw={'a','e','i','o','u'};
int count=0;
for(int i = 0 ; i< len;i++)
{
for(int j = 0; j<5;j++)
{
if((String.valueOf(v.charAt(i))).equalsIgnoreCase((String.valueOf(vw[j]))))
{
count++;
}
 }
    }
System.out.println("In this String there are "+count+" vowels and "+(len-count)+" consonant.");
   }
 }

No comments:

Powered by Blogger.