Question
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...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started