0

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");
}
4
Contributors
3
Replies
43
Views
7 Months
Discussion Span
Last Post by anand01
1

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.

Edited by JamesCherrill

0

_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?

-1

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.