Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA Write a program that reads a string entered at the command lineand counts the number of characters or words. A blank space shouldbe

IN JAVA

Write a program that reads a string entered at the command lineand counts the number of characters or words. A blank space shouldbe used to delimit a word. Name the program StringCount and designit to be invoked using syntax as follows: StringCount –[c][w]user_string The hyphen (-) in the above syntax is used to denotethat counting options will be specified and the square brackets areused to denote counting options. A ‘c’ indicates that a charactercount should be done and a ‘w’ indicates that a word count shouldbe done. As an example, StringCount –cw "hello world" indicatesthat a character count and word count should be done on the string"hello world", and StringCount -w "hello world" indicates that aword count should be done on the string "hello world". Separatemethods must be used to perform the counts. Note that if the stringcontains blanks, as in the above example, then the string must bequoted and the quotes will not be part of the count. If a user runsthe program with incorrect syntax (e.g., the type of count is wrongor missing) the program should display an error message indicatingthe correct syntax (just use the above syntax). If you are using anIDE you may have to consult its documentation to learn how commandline arguments are entered. If you have trouble finding thisinformation you can always run the program from the commandline.

Step by Step Solution

3.43 Rating (156 Votes )

There are 3 Steps involved in it

Step: 1

Answer and step by step explanation We can create the program to count the characters and words of a string entered at the command line in Java as fol... 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

Data Structures and Algorithm Analysis in Java

Authors: Mark A. Weiss

3rd edition

132576279, 978-0132576277

More Books

Students also viewed these Programming questions