Write a Java program that reads in a paragraph of text from a file and prompts the user to enter a word to search for. The program should then output the number of times the word appears in the paragraph. Here are the basic steps to implement this program:
Write a Java program that reads in a paragraph of text from a file and prompts the user to enter a word to search for. The program should then output the number of times the word appears in the paragraph.
Here are the basic steps to implement this program:
-
Prompt the user to enter the name of the input file.
-
Read in the paragraph of text from the input file.
-
Prompt the user to enter a word to search for.
-
Search the paragraph for the word and count the number of times it appears.
-
Output the number of times the word appears in the paragraph.
To implement step 4, you can use a similar approach to the example I provided in class:
-
Split the paragraph into an array of words using the split() method.
-
Iterate through each word in the array and compare it to the search word (ignoring case).
-
If the word matches the search word, increment a counter variable.
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 5 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)