/* In this program , we are taking out the number of vowels, words and sentences in a paragraph
* We first run a loop to take out each character of the paragraph
* Then we check whether the it is the end of the sentence which is marked by '!' , '.' or '?'
* If it is the end of the sentence , then we take out each word from the sentence
* From each word we extract each alphabet
* Then we check whether the alphabet is a vowel or not
* So here we go :
*/
class Parts_of_a_paragraph//Here have assumed that there is no space between the ending alphabet of the sentence and '.' , '?' or '!' and also between the first alphabet of the next sentence{
void main(String paragraph)
{
paragraph = paragraph+" ";
int len = paragraph.length() , no_sentence = 0 , no_vowel = 0 , no_word = 0 ;
String word = "" ;
String sentence ="" ;
char character , var , ch;
System.out.println("Sentence No. of vowels No. of words");
for(int i = 0 ; i<len ; i++)
{
character = paragraph.charAt(i);//To extract the each character from the paragraph
if((character=='.')||(character=='!')||(character=='?'))//check whether it is the end of the sentence
{
no_sentence++;
sentence = sentence+" ";
for(int j = 0 ; j<(sentence.length()) ; j++)
{
var = sentence.charAt(j);//To extract each character from the sentence
if(var==' ')//to check whether it is the end of the word
{
word = word +" ";
no_word++;
for(int v = 0 ; v<(word.length()) ; v++)
{
ch = word.charAt(v);//To extract each character from the word
if((ch=='a')||(ch=='A')||(ch=='E')||(ch=='e')||(ch=='I')||(ch=='i')||(ch=='o')||(ch=='O')|| (ch=='u')||(ch=='U'))//to check whether ch is a vowel
{
no_vowel++;
}
else
;//a null statement
}
word = "";
}
else
{
word = word + var ;
}
}
System.out.println(" "+no_sentence+" \t "+no_vowel+" "+no_word);
no_vowel = 0 ; no_word = 0 ;
sentence = "";
}
else
sentence = sentence + character;
}
}
}
PLEASE GIVE SUGGESTIONS AND ASK QUESTIONS DOWN IN THE COMMENTS SECTION
No comments:
Post a Comment