Computer Science, asked by 21palak111, 1 year ago

write a program to assign and print the number of vowels in the last word of string...

Answers

Answered by prathamesh1855
1
1     public class CountVowels {3    public void count(String str) {4        int count = 0;5        for (int i = 0; i < str.length(); i++) {6            char ch = str.charAt(i);7            if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {8                count++;9            }10        }11        System.out.println("Number of vowels : " + count);12    }13}
Answered by Anonymous
33
ANSWER
.............




/* * C program to read a sentence and count the total number of vowels


 * and consonants in the sentenc



. */#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);}
Similar questions