write a program to assign a string and print the number of vowels ,blank spaces and words.
please answer this question................
I WILL MARK YOU AS BRAINLY..................
Answers
Explanation:
import java.util.*;
class Count
{
public static void main(String args[])
{
int i,vowels=0,consonants=0,spaces=0;
String s;
Scanner sc = new Scanner(System.in);
System.out.println("Enter sentence");
s=sc.nextLine();
char str[] = s.toCharArray();
int n= str.length;
for(i=0;i<n;i++)
{
if(str[i]=='a' || str[i]=='e' || str[i]=='i' ||str[i]=='o' || str[i]=='u' || str[i]=='A' ||str[i]=='E' || str[i]=='I' || str[i]=='O' ||str[i]=='U')
{
vowels++;
}
else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z'))
{
consonants++;
}
else(str[i]==' ')
{
spaces++;
}
}
System.out.println("Vowels = "+vowels);
System.out.println("Consonants = "+consonants);
System.out.println("White spaces = "+spaces);
}
}