Java language problem Provide comments classes and all the

Java language problem

( Provide comments, classes, and all the steps to solve this problem )

Problem:
Write a program CountWords in Java that reads text from a file and breaks it up into
individual words. Insert the words into a tree set. At the end of the input file, print all
words, followed by the size of the resulting set. This program determines how many unique
words a text file has. If the file is not found, give the user a chance to select another file.

Solution

Answer:-

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class WordCount {
  
public static void main(String[] args) throws IOException {
System.out.print(\"Please enter a string: \");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String string = reader.readLine();
  
String[] words = string.split(\"\\\\s+\"); // match one or more spaces
  
System.out.println(\"\\\"\"+string+\"\\\"\"+\" has \"+words.length+\" words\");
System.out.println(\"The words are, \");
for(int i =0;i<words.length;i++) {
System.out.println(words[i]);
}
}
}

Java language problem ( Provide comments, classes, and all the steps to solve this problem ) Problem: Write a program CountWords in Java that reads text from a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site