Program to count the total number of vowels and consonants in a string.
public class HelloWorld{
public static void main(String []args){
String file = "This is a really simple sentence";
int count = 0;
int count1 = 0;
for(int i =0 ;i<file.length();i++){
char v = file.charAt(i);
if(v=='a' || v== 'e' || v=='i' || v=='o' || v=='u'){
count++;
}else
{
count1++;
}
}
System.out.println("it is a vowels "+count);
System.out.print("it is a consonants "+count1);
}
}
Comments
Post a Comment