OneCompiler

Count the no. of Vowels, Consonants, Digits, Spaces and Symbols in a given String ?

1649

import java.util.*;

public class Main
{
static void cntVow(String a)
{
int n=a.length();
int vow=0,cons=0,dig=0,sp=0,sy=0;
for(int i=0;i<n;i++)
{
char x=a.charAt(i);
if(x=='a'||x=='A'||x=='e'||x=='E'||x=='i'||x=='I'||x=='o'||x=='O'||x=='u'||x=='U')
vow++;
else if((x>=65 && x<=90) || (x>=97 && x<=122))
cons++;
else if(x>48 && x<=57)
dig++;
else if(x==32)
sp++;
else
sy++;
}
System.out.print("Vowel-"+vow+'\n'+"Consonant-"+cons+'\n'+"Digits-"+dig+'\n'+"Space-"+sp+'\n'+"Symbol-"+sy);
}
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
String a=s.nextLine();
cntVow(a);
}
}