0% found this document useful (0 votes)
3 views2 pages

Vowel and Consonant Counter in Java

Uploaded by

khatoonshamiya96
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Vowel and Consonant Counter in Java

Uploaded by

khatoonshamiya96
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

QUESTION:

WAP to enter a sentence which will be terminated by ‘.’ ‘?’ or ‘!’ only. Convert it into Uppercase and
perform the following tasks,
a. Count the number of vowels and consonants of each word.
b. Print the frequency of vowels and consonants in the form of bar graph where V denotes vowels and
C denotes consonants.
INPUT:
How are you?
OUTPUT:
HOW ARE YOU?
WORD COUNT
HOW V
CC
ARE VV
C
YOU VV
C

INPUT:
How are you#
OUTPUT:
Wrong terminating character

ANSWER:
CODING:
import [Link].*;
public class VCGraph
{
void graph(String s)
{
s=[Link](0, [Link]()-1);
StringTokenizer tk = new StringTokenizer(s);
[Link]("WORD\tCOUNT");
while([Link]())
{
int v=0, c=0;
String w = [Link]();
[Link](w+"\t");
for(int i=0; i<[Link](); i++)
{
if("AEIOU".indexOf([Link](i)) != -1)
v++;
else
c++;
}
for(int i=0; i<v; i++)
[Link]("V");
[Link]("\n\t");
for(int i=0; i<c; i++)
[Link]("C");
[Link]();
}
}
public static void main()
{
Scanner sc = new Scanner([Link]);
VCGraph ob = new VCGraph();
[Link]("Enter a sentence");
String st = [Link]();
st = [Link]();
char c = [Link]([Link]()-1);
if(c=='.' || c=='?' || c=='!')
{
[Link](st);
}
else
[Link]("Wrong terminating character");
}
}

OUTPUT:
Enter a sentence
how are you?
WORD COUNT
HOW V
CC
ARE VV
C
YOU VV
CC

Enter a sentence
have a good day#
Wrong terminating character

You might also like