Question: Java Write a program that reads all words from a file and, using a Stream, prints how many of them are the word the. This
Java
Write a program that reads all words from a file and, using a Stream, prints how many of them are the word the.
This is my current code:
import java.io.File; import java.io.IOException; import java.util.Scanner; import java.util.*;
/** * * Write a program that reads all words from a file and, using a Stream, * * prints all distinct words with at most four letters. * * from Horstmann, Big Java 6th Ed. */
public class PrintDistinctWords {
public static void main(String[] args) throws IOException {
String filename = "DeclarationOfIndependence.txt"; // Uses try-with to open the file
try (Scanner in = new Scanner(new File(filename))) {
// Read all the words in the file //declaring a Map to store all words and its count HashMap
// now iterating through map and checking non-repeating words for(Map.Entry
} } }
how will I change it too look for the word the instead of a word with a length of 1 to 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
