Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Help!!!! Write a method that allows counting words in a string: int wordCount(String s) {... Write a main program that asks the user for

Java Help!!!! Write a method that allows counting words in a string:

int wordCount(String s) {...

Write a main program that asks the user for an input string, calls your method on the string, and prints out the number of words in the string without using predefined methods of the String class.

The assumption is that words are separated by spaces, however, not necessarily a single space. Counting spaces will not always give the correct answer. You have to detect groups of spaces and count them as a single separator. "Hello world" with one space and "Hello world " with ten spaces between the words and 3 trailing spaces at the end must both yield same answer: 2 words. Do not use any predefined methods of the String class. You need (a) loop(s) and (an) if-statement(s) to write your own logic.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

=+ d. a professor deciding how much to prepare for class

Answered: 1 week ago