wap to find the vowels from each and every word of the sentence
Answers
Answer:
public class Hello{
public static void main(String []args){
String abc = "My name is ElegantQueen";
int count = 0;
for (char c: abc.toCharArray()){
if(c == 'a' || c =='e' || c=='i' || c=='o' || c=='u' || c=='A'||c=='E' ||c=='I'||c=='O'||c=='U'){
count++;
}
}
System.out.println(abc +" has " +count +" vowels");
}
}
Explanation:
#function
public class Hello{
public static int vowel(String str) {
int count = 0;
for (char c: str.toCharArray()){
if(c == 'a' || c =='e' || c=='i' || c=='o' || c=='u' || c=='A'||c=='E' ||c=='I'||c=='O'||c=='U')
count++;
}
return count;
}
public static void main(String []args){
String abc = "My name is ElegantQueen";
int count=vowel(abc);
System.out.println(abc +" has " +count +" vowels");
}
}
****hope it helps*****
/*
* C program to read a sentence and count the total number of vowels
* and consonants in the sentence.
*/
#include <stdio.h>
void main()
{
char sentence[80];
int i, vowels = 0, consonants = 0, special = 0;
printf("Enter a sentence \n");
gets(sentence);
for (i = 0; sentence[i] != '\0'; i++)
{
if ((sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] ==
'i' || sentence[i] == 'o' || sentence[i] == 'u') ||
(sentence[i] == 'A' || sentence[i] == 'E' || sentence[i] ==
'I' || sentence[i] == 'O' || sentence[i] == 'U'))
{
vowels = vowels + 1;
}
else
{
consonants = consonants + 1;
}
if (sentence[i] =='t' ||sentence[i] =='\0' || sentence[i] ==' ')
{
special = special + 1;
}
}
consonants = consonants - special;
printf("No. of vowels in %s = %d\n", sentence, vowels);
printf("No. of consonants in %s = %d\n", sentence, consonants);
}