I'm scanning my text and I want to add them into array list, but it is not easy. I want each word store from arrayList of a to z which is arrayList size is 26. Example:
arrayList a store string array of: an, and, apple, ...
arrayList b store string array of: be, become, became.....
.
arrayList z store string array of: zero, zone...
In my class, I create:
private static ArrayList<String[]> words = new ArrayList<String[]>(26); // to store all words
In main, I do while loop to get each words and store in words array,
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
public class BinaryTree {
I am having a lot of trouble with this lab. basically I have to make a text processor to read in code put it into a file and output the contents of the input file in alphabetical order one word per line. I have to reference the string varaibles input_filename and output_filename.
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; import java.io.File; public class TextProcessor {
[Code] ....
these are the guidelines to said lab:
1. In the main method define two Strings called input_filename and output_filename. I will be setting these Strings to my own file names for testing your code, so make sure you get these variable names correct, and that you use them properly in the following steps. 2. Read in the text contents of the file referenced by input_filename. 3. Split the contents of the input text into separate tokens, using whitespace as a delimiter. 4. Lower case the tokens. 5. OPTIONAL: remove punctuation 6. Alphabetize the tokens. 7. Using output_filename, write the alphabetized tokens to an output file, one token per line. 8. Be sure to close file streams - no resource leaks! 9. Use methods to separate functionality in your program where possible
I was trying to do a short program that scans a text for a given word and then tells you how many times that word was repeated in the text. The result was this:
var text = prompt("Write the text to be searched through"); var word = prompt("Write the word to be looked for. Beware of capitals!"); var hits = []; for (var i = 0; i < text.length; i++) { if (text[i] === word[0]) {
[Code] ....
However, this doesn't scan the text properly. I think the problem lies in one of the lines from 4 to 8, but, even after thinking quite a lot, I couldn't understand what was it. I thought that by saying that the letter of the text in position [i + k] shuold be equal to the letter of the word in position [k] I could make it work, but it doesn't.
The intentions of this program is to prompt a user to enter a file name, and then reads the file. The program will prompt the user to enter a word that needs to be corrected. So lets say I have a text file containing "My name is OP and I Like goind to the Park!" I want to change "goind" to "going",
Now, my second method "isSimilar" executes a similar word with more than one same letter and same length, but I dont know how to execute that whole thing in my third method "correctThisLine" . How I can call that isSimilar method and read in that text file and change that word into that?
import java.util.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class WahidMuhammadA3Q2{ String fileName = "AutoCorrectMe.txt"; public static void main (String [] args){
I need a java code to search a certain word from the text file. the word that i want to search is in other text file. and finally the output will print the result in the new text file. for the example the text file name data.txt and the word list in the wordlist.txt and the output will print filter.txt.
This part of the code searches for every word in the text file and saves it to an ArrayList. It searches for the word if its valid of not.How can I offer a list of similar words when the word that the user inputs is not in the dictionary. Also I want it to prompt the user to accept the word or enter a replacement that gets saved in the dictionary.
I am quite new to java and trying to print all the system properties with the following
code:System.out.println(System.getProperties());
This prints all the properties as expected but I am wanting to put each property on a new line and am struggling a bit. Obviously I will need some sort of for loop etc but im just not sure how to do it. Is it something along the lines of:
for (int i = 0; i < System.getProperties().size(); i++){
What my understanding of what the above is doing is checking how many properties there are an looping round for each property that exists, so all I need to do is get the property 1 at a time however I am not sure where to get the property value to input into the System.getProperty(); method.
Why is it simple for a word processing software (one that reads number of words, words greater that x characters etc) to deal with text file(.txt) and not with a doc file (.doc) file?? Is there any special requirements or what are the points taken into consideration while developing the software for a .doc file?
I am trying to do is extract numbers that are in word format in a long String, i.e. a song, and return each of their numerical values, in order to add them all up. So I'd like to calculate the sum of all of the numbers in the text. This has to work for any piece of text and for all numbers up to a trillion.
So I broke the string down into tokens and stored them in a String []. And I divided up the possible numbers in word format into:
I believe that these are the only words that it will need to recognize. I began reading the tokenized string from right to left and then when I came across a unit, special or tens as the first number I hit, I would then set it's numerical value and check if the word before was also a number and whether to add or multiply etc. i.e. First number hit is a two, if the number before is sixty, then I would just add it to sixty and check the word before that and so on.
However, when implementing it, it seems like an extremely long way around it. How I could implement this in a swifter manner? An example of it working would be:
"Nine Million rockets turned Three times and met Twenty Two Aliens", it would extract, Twenty Two as 2, then 20 = 22, then extract Three as 3, and then Nine Million as 1,000,000 x 9 = 9,000,000
Consider in a Document if a String " Hello" is Encoded and stored as "XYZAB"
I want to search the text on document for a word "Hello" and Replace the word with "HelloWorld"
The Program will encrypt the word "Hello" and Search the file then return the encrypted code as "XYZAB" Found
Now i have to replace the word "Hello" with "HelloWorld" in encrypted form so that the Letter "XYZABEFGHI" is replace in the place of Hello where "World" is encoded as "EFGHI"
Now the Problem is If there is more number of occurrence of the word "Helloworld" exist in the file... How can i Replace only one particular occurrence What can be done to select the particular occurrence.
I have attached my java program for Encryption along with this mail for your ease of use.
I'm making a class in Android that takes a photo, list a photos in Listview, and then sends them all to server. I'm stuck on listing them. How to send them all to server.
I am trying to sort an array that I have by alphabetical order but I am having problems. Firstly the code that I have used to sort the array may not even do what I need but havn't got far enough to test it yet so go easy on me . I have read in some places when searching how to do this that I would have to create my own bubble sort in order to achieve this but I was hoping that Java had a built in sort method/function. Secondly I lack the knowledge in java to be able to assign an existing array or even a variable to the newly sorted array as I need the unsorted version with the original name and the newly sorted version as another.
code (This is not all of the code, I decided to include only what I thought was relevant):
import java.util.Arrays; public class Sentence { private String words[]; public Sentence(String[] words) { this.words = words; } @Override public String toString() { return "Sentence{" + "words=" + Arrays.toString(words) +
[Code] ....
Is it possible to shorten the sort function to just this?
public String sorted() { return Arrays.sort(words); }
I'm doing an exercise we're you're supposed to sort strings in alphabetical order, without importing anything , not using the Arrays.sort() method.
I think I got the method down partially right, or it is on the right track, but it is completely not being applied to my answer. All it prints out in the console is the actual String array twice, without sorting anything.
public class arrayofstrings { public static void sort(String[] a) { String temp= ""; int min; int i= 0; for (int j=0; j<a.length-1; j++) {
I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.
As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?
public void findUnique() { System.out.println("There are " + findUniqueWords(root, 0) + " unique words."); } private int findUniqueWords(Node subTree, int uniqueCount) { // Base Case: At the end of the branch if(subTree == null){ return uniqueCount;
I am looking for java codes to generate a word document based on a word template, basically, I have a word template created and in my local path, the template has a proper format with some fields which will be filled in after java codes ran. The java codes will fetch one record from a table, and open the word template and then fill the fields in the word template, and created a new word document and save it in another folder.
I found this example: [URL] which is similar except it uses xml template instead of word template, how to make it work to change the template from xml to word (docx) template?
package bin; import java.util.Scanner; public class AppletMain{ public static void main(String[] args){ Scanner oneinput = new Scanner(System.in); String one;
[Code] ....
I am trying to get it to compare the word I type in to the set word in the object 'secretword'. I have tried everything from equal to == to compareTo, I even created a two hundred line program to do this SIMPLE problem.
import java.io.*; import java.util.Random; import java.util.Scanner; public class WordGame { public static void main(String[] args) throws IOException { final int RANDOM_LETTERS_COUNT = 10; final int TRIALS = 10; int score = 0;
what weapon the user wants to use and set the element of the Player but I can't use defineWeapon() inside of the constructor so what can I do?here's the player class (where I need to set the element which is the second string in the constructor
package netHackDessart; import java.util.Scanner; public class Player extends Monster { public Player() { super("player", "null", 18, 6, 150, 4, 1, 6, 1, 8, 1, true, false);
I want to find a certain element in array I have to scan through the array index starting from 0 until I find the number I am looking for. Even in data structures which use hashing like HashMap and Hashtable we will have to scan through the keys until we find the key we are looking for. So what is the use of hashing over index based searching? I mean how is hashing an advantage over an array?
I have task for last years in campus , how do you scan document with scanner peripheral in java program? I have browsing on internet, and I have an API like TWAIN.
I need to create a program that uses ArrayList to store integers the user inputs, then scan the array for the largest number. I would also like the user to be able to exit this loop if the number 0 is entered.
As you can see below, I'm not sure how to correctly exit the do-while loop. I found this on another forum, but it does not work.
Java Code:
import java.util.*; public class array { public static void main(String [] args){ ArrayList<Integer> list = new ArrayList<Integer>();
I am thinking of a project for my university the teachers liked it but I am not sure if its even possible.I am trying to make an andriod app. What I want to do is take a picture of a hand drawn logic circuit (having the AND, OR, NOT ... gates) recognize the gates, and make a circuit in the moblie and run it on all possible inputs.
For this I will have to make a simulator on mobile, that I dont think is the hard part. The problem is how could recognize the gates from a picture. Example of logical circuit is attached ( assume its hand drawn )..I found out that theres a edge detection plugin in java but still I dont think its enought to recognize the gates. Please share any algorithm or any technique or tools that I can use to make this thing.