Computer Science, asked by Elegantqueen2006, 1 year ago

wap to find the vowels from each and every word of the sentence​


sswaraj04: which programming language
sswaraj04: wait few mins

Answers

Answered by sswaraj04
1

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*****


sswaraj04: 12
sswaraj04: do you wanna ask something
sswaraj04: ok ....i got notifications lol
sswaraj04: thx for brainliest
sswaraj04: ya asking for help.....
Answered by Ranauk456
1

/*

* 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);

}


Ranauk456: uph
Ranauk456: you had to tell me first. now the time of editting has gne
Ranauk456: can you ask it again?
Ranauk456: welcome
Similar questions