Computer Science, asked by coachaloke, 5 months ago

Write a program to enter the sentence and count the occurrence of vowels in each word.

Example: Enter sentence : Sharada Mandir celebrates Golden Jubilee Year

Output:
Sharada : Number of vowels=3
Mandir : Number of vowels=2
celebrates : Number of vowels=4
Golden : Number of vowels=2
Jubilee : Number of vowels=4
Year : Number of vowels=2​

Answers

Answered by anindyaadhikari13
0

Required Answer:-

Question:

  • Write a program to enter the sentence and count the occurrence of vowels in each word.

Solution:

Here comes the códe.

1. In Java.

import java.util.*;

public class Words {

public static void main(String[] args) {

String s, x[];

int i;

Scanner sc=new Scanner(System.in);

System.out.print("Enter a Sentence: ");

s=sc.nextLine();

x=s.split(" ");

for(i=0;i<x.length;i++)

System.out.println("Number of vowels in "+x[i]+" = "+countVowels(x[i]));

sc.close();

}

static int countVowels(String s) {

int c=0, i;

s=s.toLowerCase();

for(i=0;i<s.length();i++) {

char ch=s.charAt(i);

if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')

++c;

}

return c;

}

}

2. In Python.

def countVowels(x):

c=0

for letter in x:

if letter in "aeiouAEIOU":

c+=1

return c

s=input("Enter a Sentence: ")

x=s.split(" ")

for str in x:

print("Number of vowels in ",str," = ",countVowels(str))

Algorithm:

  1. START
  2. Accept the sentence.
  3. Split the sentence into words.
  4. Count vowels in each word and display it.
  5. STOP

Refer to the attachment for output ☑.

Attachments:
Similar questions