Counting Vowel’s & Consonant’s {JAVA}

​import java.io.*;

class Count
{   public static void main(String args[])throws IOException   {

String s=new String();
int v=0,d=0,c,i;


DataInputStream in=new DataInputStream(System.in);
System.out.println(“Enter a String:”);
s=in.readLine();

for(i=0;i<s.length();i++)
{

c=s.charAt(i);

if(c==’a’||c==’e’||c==’i’||c==’o’||c==’u’||c==’A’||c==’E’||c==’I’||c==’O’||c==’U’)
v++;

else if((c>=’a’ && c<=’z’)||(c>=’A’ && c<=’Z’))
d++;

}
System.out.println(v+”vowels\n”+d+”consonants”);
}
}

NOTE : Using Scanner Instead of DataInputStream Is Always Prefered Bcoz it will throw less warnings and also reduce syntactical errors .

  • < OUTPUT >
  • lenovo@lenovo-ThinkCentre-M71e:~/Desktop/prog$ java Count
  • Enter a String:
  • Hello Guys This Is MrWhoztheBoss.
  • 8vowels
  • 20consonants

{ Click Me TO Download }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s