JAVA: Make a single-threaded program that counts words in a text file and prints the result in an output.txt
example:
if a input.txt file has a string "There was an apple, which was in there.", the output.txt should have:
there: 2
was : 2
an : 1
apple : 1
which :1
in : 1
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
try
{
//variable declaration
int wordCount;
String input = "";
String line = null;
FileReader fr=new FileReader("input.txt");
BufferedReader br=new BufferedReader(fr);
BufferedWriter writer = new BufferedWriter(new
FileWriter("output.txt"));
while ((line = br.readLine()) != null)
{
input += line;
}
String inputLC = input.toLowerCase();
String[] words=inputLC.split(" ");
wordCount = 1;
for(int i=0;i<words.length;i++)
{
for(int j=i+1;j<words.length;j++)
{
if(words[i].equals(words[j]))
{
wordCount=wordCount+1;
words[j]="0";
}
}
if(words[i]!="0")
{
//write into the output.txt file
writer.write(words[i]+" : "+wordCount+"\n");
}
wordCount=1;
}
writer.close();
}
catch (IOException e)
{
System.out.println(e);
}
}
}
OUTPUT:
output.txt

JAVA: Make a single-threaded program that counts words in a text file and prints the result...
JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...
JAVA: create a program that reads all text files in a directory, calculates the occurrences of words, and saves the result in one single output text file. assume that you are in a directory called Desktop/programdirectory, where you have multiple text files. textfile1.txt : "how are you" textfile2.txt: "great thank you" textfile3.txt: "great to see you. see you later" Then, your output.txt should have: how: 1 are: 1 you: 4 great: 2 thank: 1 to: 1 see: 2 later: 1
python
Create a program to open a text file for reading, find the maximum number in the file, determine if that maximum number is even, and write to an output text file. You should either write Yes if the number is even, otherwise write the maximum number. You should note the following: • Your input file must be named input.txt • The input file has one integer number per line • Your output file must be named output.txt • Your...
Write a Java program that reads words from a text file and displays all the non-duplicate words in ascending order. The text file is passed as a command-line argument. Command line argument: test2001.txt Correct output: Words in ascending order... 1mango Salami apple banana boat zebra
C++ Write a program that reads from the external file input.txt, counts the letters in every word, replaces the word by that number, and then writes the numbers to an external file output.txt (Note: Do not forget to copy the blanks. You may wish to use infile.get and outfile.put in your program.) Also you may wish to use the strlen( ) function. Output: After the program generates output.txt, the code should display the contents of the file on the screen...
Write a console program in Java that allows the user to specify a text file, opens the file, and prints a two-column table consisting of all the words in the file together with the number of times that each word appears. Words are space-delimited and case-sensitive. The table should list the words in alphabetical order. Proper code documentation should be included in the source code.
Please write a java program with a input file "jabberwock.txt", and output the "output.txt" with following requirement. You and your partner will be writing a simple Java program that implements some basic file I/O operations. You can use this code as the basis for some of your next project. FIRST: Write code that prompts the user for the name of a text file, opens that file if it exists and reads the file one line at a time printing each...
Write a program in java that asks a user for a file name and prints the number of characters, words (separated by whitespace), and lines in that file. Then, it replaces each line of the file with its reverse. For example, if the file contains the following lines (Test1.txt): This is a test Hi there Output on the console: Number of characters: 22 Number of words: 6 Number of lines: 2 Data written to the file (Test1.txt): tset a si...
Create a random access Java program to insert 3 missing words into a text file. You will be supplied with the missing words, which you may hard code in your program. You need to determine from the given text file where the words should be placed! Missing words are: details populate determine Randominput.txt Create a class to hold the x_x_x_x of a new vehicle (include make, model, type, color, number of doors and price as a minimum). Include an ___init___...
//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...