Number Of Sentences In A Paragraph
Write a program to find the number of sentences in a paragraph entered by the user. A sentence is terminated by either by ' . ' , ' ? ' or ' ! '.
/* WAP to find the number of sentences in a paragraph entered by the user.
* A sentence is terminated by either by ' . ' , ' ? ' or ' ! '.
*/
import java.io.*;
class StringQ10
{
public static void main(String arg[])throws IOException
{
int i, l, nos;
String str;
char ch;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a string : ");
str=br.readLine();
l = str.length();
// To count no of sentences
nos = 0;
for(i=0;i < l;i++){
ch = str.charAt(i);
if(ch == '.' || ch == '!' || ch == '?')
nos++;
}
System.out.println("No of sentences: "+nos);
}//end of main
}//end of class
Have something to say? Log in to comment on this post.
0 comments