Question

In: Computer Science

using java, parse a text file to answer the following question: -list sentences with the maximum...

using java, parse a text file to answer the following question:
-list sentences with the maximum number of occurences of the word “the” in the whole file and also list the corresponding frequency. (cannot use hash maps)

example output:
the:3:The day had came to leave before the storm.
What hit the back bumper of the car before the window cracked?
The classroom doors where shut closed before the students open the project.

Solutions

Expert Solution

import java.io.*;
public class TheWord
{
   public static void main(String[] args) throws IOException
   {
       File f1= new File("input.txt");
       BufferedReader br = new BufferedReader(new FileReader(f1));
       int count=0,present;
       String[] words=null;
       String s;
       String search="the";
       while ((s=br.readLine())!=null)
       {
           words=s.split(" ");
           present=0;
           for (String word:words)
           {
               if (word.equalsIgnoreCase(search))
               {
                   count++;
                   present=1;
               }
               if (present==1)
                   break;
           }
       }
       System.out.println("the : "+count);

   }
}


Related Solutions

using java, parse a text file to be able to list the word(s) with the highest...
using java, parse a text file to be able to list the word(s) with the highest frequency in a sentence across all sentences in the whole file, also print its frequency and the corresponding sentence. cannot use hash maps. assume text file will be multiple paragraphs long.
given a input file, parse it and answer the following frequency related questions, using java. -list...
given a input file, parse it and answer the following frequency related questions, using java. -list the most frequent word(s) in the whole file and its frequency. -list sentence(s) with the max. number of occurrences of the word “of” in the entire file and also list the corresponding frequency. program has two arguments; 1st : path to the input text file 2nd : name prefix for the output files ex. $ java assgn1 “./input.txt” “output” outputs: for each question create...
How to read a text file and store the elements into a linked list in java?...
How to read a text file and store the elements into a linked list in java? Example of a text file: CS100, Intro to CS, John Smith, 37, 100.00 CS200, Java Programming, Susan Smith, 35, 200.00 CS300, Data Structures, Ahmed Suad, 41, 150.50 CS400, Analysis of Algorithms, Yapsiong Chen, 70, 220.50 and print them out in this format: Course: CS100 Title: Intro to CS Author: Name = John Smith, Age = 37 Price: 100.0. And also to print out the...
java question: How would you be able to store a matrix from a text file into...
java question: How would you be able to store a matrix from a text file into a linked or doubly linked list, if you cannot use 2D arrays? input example: 1 2 3 4 1 3 2 4 4 2 3 1
In linux , Using a simple text editor, create a text file with the following name...
In linux , Using a simple text editor, create a text file with the following name "Test" and content: GNU GENERAL PUBLIC LICENSE The GNU General Public License is a free, copy left license for the GNU General Public License is intended to guarantee your freedom to GNU General Public License for most of our software; it applies … 2-Write the command to create the text file. 3-Print the file permissions. 4-Create a directory named "361" 5-Copy file "Test" to...
Java Code using Queue Write a program that opens a text file and reads its contents...
Java Code using Queue Write a program that opens a text file and reads its contents into a queue of characters, it should read character by character (including space/line change) and enqueue characters into a queue one by one. Dequeue characters, change their cases (upper case to lower case, lower case to upper case) and save them into a new text file (all the chars are in the same order as the original file, but with different upper/lower case) use...
Java Code using Stack Write a program that opens a text file and reads its contents...
Java Code using Stack Write a program that opens a text file and reads its contents into a stack of characters, it should read character by character (including space/line change) and push into stack one by one. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse of their order in the first file. Ex input file: Good...
Using JAVA Resource: "Analyze and Document JDBC API Calls" text file ** PASTED BELOW** For this...
Using JAVA Resource: "Analyze and Document JDBC API Calls" text file ** PASTED BELOW** For this assignment, you will analyze code that uses the JDBC API to access a database, retrieve data, and compose output based on that data. You will then comment the code to reflect the purpose and expected results of the code. Download the linked TXT file, and read through the Java™ code carefully. Add your name, instructor's name, and today's date to the header comment. Replace...
USING JAVA A method that parses the valid word file to a list of Strings. You...
USING JAVA A method that parses the valid word file to a list of Strings. You may use a loop in the parsing method. A nonrecursive method that prints the input String, makes the first call to the recursive anagramizer method, sends the result to the filter method, and prints the filtered result. You may use this code: private void anagramize(String inString) {         System.out.println("input string: " + inString);         List < String > l = filter(anagramizeRecursive(inString.toLowerCase()));         System.out.println("Anagrams: " + l); }
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT