Saturday, December 15, 2012

count number of sentence in paragraph(sentence end with '.' or '?')

public static int countNoOfSentance(String str){
        StringBuffer strBuffer = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) != '.' && str.charAt(i) != '?') {
                strBuffer.append(str.charAt(i));

            } else {
                ++count;
                strBuffer = new StringBuffer();
            }
        }
        count++;
        System.out.println(count);
        return count;
    }


No comments:

Post a Comment