Question: Task 4 (15 pts.) The program task4.java given below is an incomplete program. The goal of the program is to take as input sentences from



Task 4 (15 pts.) The program task4.java given below is an incomplete program. The goal of the program is to take as input sentences from the user, and then print out the number of words in each sentence. Complete that program, by defining a count_ words function that satisfies the following specs: Function count_words takes one argument, called text, which is a string, and which is allowed to contain only uppercase letters, lowercase letters, and the space character. In other words, don't worry about handling cases cases where text contains characters that are punctuation, special symbols, or anything else that is not a letter or the space character. Function count words counts and returns the number of words in text. The strategy for counting words is simple: You initialize your counter to zero if your text starts with a space character, or to 1 if your text starts with a letter. You go through the text, character by character. You increment your counter every time you find a letter whose previous character was space. For example, if your current character is 'm' and the previous character was", it means that you have found a new word. 1. 2. It may be that the text starts with multiple spaces, or that multiple spaces are placed between two words. Your code should handle that correctly. IMPORTANT: you are NOT allowed to modify in any way the main function. This is an example run of the complete program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
