public static void sentencesChecker(String essay) {

    int count = 0;

    int countcap = 0;

    int i , j;
    for ( i = 0; i < essay.length(); i++) {

        if (essay.charAt(i) == '.') {
            count++;
        }
       for ( char e= 'A'; e<='Z';e++) {
           if (essay.charAt(i)==e){

                countcap++;
           }

        }

    }

    System.out.print("\n\t\t" + countcap + "out of " + count + "sentences start with a capital letter");
}
Re: How to find how many sentences start with a Capital letter 80 80

I see you failed to test this code, because it doesn't get anywhere near the stated functionality.
If you don't understand why try these test strings:

"This data has one sentence starting with a CAPITAL letter."
"this has none, says James."
"An ellipsis looks like this: ... .
"É is a latin capital letter E acute, Unicode: U+00C9, UTF-8: C3 89."
"What about this one? It has zero periods!"

.., ad that's without getting into what happens if any of the interesting characters are inside a quotation.

Listen: It's good that you are posting and contributing here, but for your own reputation you should be more careful about the quality of what you post.

Re: How to find how many sentences start with a Capital letter 80 80

_Anu_6,
Have you made any progress on testing your sentencesChecker(String essay) {.....} function as suggested by JamesCherrill?
Do you know how to test the your code?

Re: How to find how many sentences start with a Capital letter 80 80

Anu_6 ,
To find a sentences start with a capital letter read a first word of the sentence and check is start with upper case.
Character.isUpperCase(word.charAt(0))
-Anand

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.