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 doing an assignment where I have to find the price per square inch of a pizza, compare them and display the results. I have everything figured out with the values and stuff. Now when I have to displays the results I have to display which of the two pizzas is more favorable.
I have both values / square inch for both. and I know how to find the minimum value of the two wit the Math.min class. My question is how can I assign the char, PIZZA A to the value that I had so I can display it in the output statement, without writing PIZZA A. It should display after the difference is calculated.
Here's my code so far.
// This programs finds the price per square inch of a pizza
import java.util.Scanner; import java.text.DecimalFormat; public class PizzaSquareInches { public static void main(String[] args) { Scanner input = new Scanner(System.in); DecimalFormat df = new DecimalFormat("#.###");
At first I wanted to just use an array and set each day a value, however I was told that it has to be stored as a string.
Design and implement the class Day that implements the day of the week in a program. The class Day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type Day:
A. Set the day. B. Print the day. C. Return the day. D. Return the next day. E. Return the previous day. F. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add four days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday. G. Add the appropriate constructors. H. Write the definitions of the methods to implement the operations for the class Day, as defined in A through G. I. Write a program to test various operations on the class Day.
import java.util.*; public class Day { static Scanner readinput = new Scanner(System.in); String day; public Day(String day) {
[Code] ....
So right now if I run my code it allows me to type in a day, then it gives me the next and previous day, the last part is to add X days to it. Ideally I would like to be able to take the day entered, depending on the day set a numeric value, then add prompt for number of days you want to add. The program should then use modal (%7 ) to add value to the value that was given based on the day, and then translate it back into a String value (the day).
I am getting an error stating that 'word cannot be resolved to a variable' pointing to my return value. Why? Should I make a default String value for word before my while loop or something, like
String word = " "; ?
String getItRight(){//make sure the user enters the password correctly Scanner input = new Scanner(System.in); boolean repeating = true; while(repeating){
So the exercise I'm working on says to have the user enter their name and the program will output their name with the last name in all caps. i made it work BUT the only way i could figure it out was to ask for the first and last names separately creating two strings rather than one.
Of course I want to make it work how it's supposed to (with one string) so that I'm learning. I'm just having trouble conceptualizing how exactly (with varying lengths of names) to tell the program to only capitalize the second word... at first I thought create a substring beginning with the first letter of the last name and ending with the last...but again, therein lies the issue of varying name lengths.
is there a way to create a substring that beginIndex's at the first "space"? then i could just leave the endIndex parameter empty and it would take the whole word into a new string. and from there utilize toUpperCase to the new string?
Here's my code asking for the first and last names separately.
import java.util.Scanner; class nameEcho { public static void main ( String [] args ) { Scanner scan = new Scanner( System.in ); String first; String last;
I'm very new to Java, and I'm writing a code to search a string to see how many times the word "dog" is found in it. I'm not sure if this is error-free or the most efficient, but I'd like to keep it simple.
public void run() {
String input = new String("The Dogman was no ordinary dog, nor man, but rather a peculiar dog-like man who barked like a dog, and panted like a dog, he even ate like a dog. He owned a dog named Doglips, and interestingly enough, his favorite food was hotdogs.");
println(input); int index = -1; int count = 0; print("Counting dogs:"); inputarray = input.split(" ");
What I need to do is ask the user to input some text and then turn it into pig latin. I am confused on how to select each word from the string to determine if it ends in a way or ay. I am to assume that the letters are all lowercase and the text ends with a period.
import java.util.Scanner; public class Trial { public static void main(String [ ] args) { Scanner input = new Scanner(System.in);
I have the following code in which I am looping through the rows of one array (composed of Strings) and copying it to another array. I am using .clone() to achieve this and it seems work as it changes the memory location of the rows themselves. I did notice that the String objects are still pointing to the same location in memory in both arrays but I won't worry about that for now, at the moment I just want to understand why the array I am cloning is not successfully assigning to the other array.
This is the incorrect line: ar[r] = maze[r].clone();
I am looking for a way to create a method with the initial state in while loop, which will count the length of each word in a string using I want the output to be something along the lines of:
hello world how are you There are 0 words of length 0 There are 0 words of length 1 There are 0 words of length 2 There are 3 words of length 3 There are 0 words of length 4 There are 2 words of length 5
This is my code so far it sort of does the job but not the way i want it too
import java.util.Scanner; import java.util.StringTokenizer; public class Brown_Matthew_13117002{ public static int count(String s, int len){ int result=0; StringTokenizer st=new StringTokenizer(s,"[ ,;]");
[Code] ....
The output would end up being :
hello There are 0 words of length 0 world There are 0 words of length 1 how There are 0 words of length 2 are There are 3 words of length 3 you There are 0 words of length 4
I am looking for a way to create a method with the initial state in while loop, which will count the length of each word in a string using I want the output to be something along the lines of:
hello world how are you There are 0 words of length 0 There are 0 words of length 1 There are 0 words of length 2 There are 3 words of length 3 There are 0 words of length 4 There are 2 words of length 5
ithis is my code so far it sort of does the job but not the way i want it too
import java.util.Scanner; import java.util.StringTokenizer; public class Brown_Matthew_13117002{
i want a simple,beginner program to accept a string from the user and display the longest word in the string.i thought of taking the length of the string and choosing the longest string.but if the user enters a big paragraph,how can i store each word in a variable??
I am looking for a way to create a method with the initial state in while loop, which will count the length of each word in a string using I want the output to be something along the lines of:
hello world how are you There are 0 words of length 0 There are 0 words of length 1 There are 0 words of length 2 There are 3 words of length 3 There are 0 words of length 4 There are 2 words of length 5
This is my code so far it sort of does the job but not the way i want it too
import java.util.Scanner; import java.util.StringTokenizer; public class Brown_Matthew_13117002{ public static int count(String s, int len){ int result=0; StringTokenizer st=new StringTokenizer(s,"[ ,;]");
[Code] ....
The output would end up being
hello There are 0 words of lenghth 0 world There are 0 words of lenghth 1 how There are 0 words of lenghth 2 are There are 3 words of lenghth 3 you There are 0 words of lenghth 4
I think I need to use string.split instead of stringtokenizer and the while loop is incorrect it needs to loop equal to the number of letters in the longest word. But how to do either of these ?
I'm trying to find a word in an array of char.....but I'm stuck. How to formulate the code to step through the array and pick out the word. This is what I have so far...
public static void searchAcross(String string, char[][] puzzle) { // Gets the number of rows in the matrix int rowLength = puzzle.length; //Gets the number of columns in the matrix. int colLength = puzzle[0].length;
I want to make a method that takes a word and then checks if the word can be created from available letters. For example, if a word "johnson" can be created by using letters "jashoqwnon".
Now my goal is to make sure that if available letters contain a letter from the word, that letter is put into a String called result and then erased from the list of given letters. So, "johnson" and "jashoqwn" would produce the result "johns" and leave "aqw" unused.
Now the problem that I am facing is that I can't get Java not to use the same letter twice. So "johnson" and "jashoqwn" still gives "johnson".
I've tried everything in my power but I am missing something. Here is my code.
public static String makeAWord(String word, String letters){ String result = ""; for(int i = 0; i < word.length(); i++){ for(int j = 0; j < letters.length() ; j++){
I'm trying to convert the first letter of every word in a String to uppercase. I've managed to isolate the first letter of every word and then make it uppercase but I don't know how to replace it.
public static StringBuffer makeUpperCase(){ String str = String.valueOf(input2); for(int i = 0; i < str.length(); i++){ if(str.charAt(i) == ' '){ char var = str.charAt(i + 1); var = Character.toUpperCase(var); System.out.println(var); } }
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 have included split() to put a string read from a given file into indexed array. Looking for a word position (not char position number in addition to the line number I have already written. Line number works fine, however word position isn't quite right.Below is my code:
import java.io.*; public class Word implements Comparable, TreeComparable{ String word; int count; int wordpos; ObjectList lines; private SuperOutput so;
I'm having an issue, I have a scanner (Scan.nextLine();) that scans the console for input to fetch the string "word". Then I want to fetch a character using Scan.findInLine(word).charAt(number);. The problem is that the console requires me to write 2 lines in order for the program to move on. I only want the program to scan for a word, and then move on with what it has instead of requiring 2 inputs.
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 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?