I have an exam coming up on this unit found in the guide to programming with Java textbook. I was just wondering if someone can provide an algorithm to the following question.

13. a.) Write an algorithm to count the number of words in a sentence.
b.) Write an algorithm to count the number of letters in a
sentence.

Please if you can just stick to loop and string methods. We have yet to cover topics such as Arrays. I have been working hard at this and would appreciate any help. Thank you in advance.

Read the rules pertaining to "we only give homework help to those who show effort", then come back and post something that shows effort. And no, it does not matter whether this is homework or not. Everything posted here falls under that rule.

I was just wondering if someone can provide an algorithm to the following question.

Yes, I am quite sure someone can. Unfortunately for you, though, that's your job in this case.

Assuming that the sentence is stored in a String variable, why don't you check the String API. We might find something there that could be useful.


PS. I didn't notice that this is my 1666 post!