1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gnesinka [82]
3 years ago
5

Write a program that reads in text from standard input (hint: use Scanner) and prints out the number of words in the text. For t

he purpose of this exercise, a word is a sequence of non-whitespace characters that is surrounded by whitespace.
Computers and Technology
1 answer:
Vitek1552 [10]3 years ago
4 0

Answer:

The solution code is written in Java

  1.        Scanner input = new Scanner(System.in);
  2.        System.out.print("Enter a text: ");
  3.        String inputStr = input.nextLine();
  4.        String wordList[] = inputStr.split(" ");
  5.        System.out.println("The number of word in the input text: " + wordList.length);

Explanation:

Firstly, create a Scanner object to read the user input text using nextLine method (Line 1-3).

Next, we can use the string split method and use single space " " as the separator to convert the input text to an array of individual word (Line 5).

We can simply use println to display the number of words in the array by using the length property of the array (Line 7). The word count is equal to the array length.  

You might be interested in
Which type of document would be best created in Word? HELLP!!!!
bekas [8.4K]
I think it’s presentation.
Like if I am right.
8 0
3 years ago
Read 2 more answers
Software that people commonly use in the workplace to make their lives easier is called?
larisa86 [58]
Its B beacause computer has made our lives very easier
7 0
3 years ago
Read 2 more answers
You are using Firefox as your
Hoochie [10]

Answer:

B. firefox add-ons..............

6 0
3 years ago
How to check if students viewed an assignment canvas.
Greeley [361]
Which app are you using?
6 0
2 years ago
To arrange data in alphabetical order quickly, you can _____ the data.
Vadim26 [7]
A. Organizing the data makes it easier to to arrange anything.
7 0
3 years ago
Read 2 more answers
Other questions:
  • Most OEMs recommend that the engine oil be replaced and a new filter installed at which of the following mileage intervals ?
    7·1 answer
  • Suppose we are comparing the implementations of insertion sort and merge sort on the same machine(You don’t need to know the alg
    13·1 answer
  • If a large organization wants software that will benefit the entire organization—what's known as enterprise application software
    7·1 answer
  • When do we use SAVE and SAVE AS in saving artwork in adobe illustrator?<br> PLEASE HELP ASAP
    11·1 answer
  • You created a database related to computer hardware parts and their details. You'd like to view the names of the parts in alphab
    9·1 answer
  • If you were a game programer (NOT using scratch or other basic software making platforms) what kind of code would you use for th
    6·2 answers
  • _________________ component defines the correct granularity for access controls and oversees the relationships between identitie
    13·1 answer
  • What is the difference between business strategies and business models?
    9·1 answer
  • Laura is confused with the spelling of the word pronunciation. She types the word as pronounciation throughout a document. Which
    14·1 answer
  • where should a user disable virus protection settings that might prevent the boot area of the hard drive from being altered? a.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!