
how to count the no. of constants in a user given string?? plzz help

Here is a code that count the number of constants from the input string.
import java.util.*;
class StringExample
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter string:");
String str=input.nextLine();
char ch[]=str.toCharArray();
int count=0;
for(int i=0;i<ch.length;i++){
if(ch[i]=='a'||ch[i]=='e'||ch[i]=='i'||ch[i]=='o'||ch[i]=='u'){
}
else if(ch[i]==' '){
}
else{
count++;
}
}
System.out.println("Number of constants: "+count);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.