combo is the private CombinationLocker object I created within the Locker class. Do I need to pass the combo object on to the CombinationLock class? For reason, I do not comprehend, the combination password from the main class is not passing through to the CombinationLock class, and the combination values are all zero.
I have a large text file of 1 GB size. I need to print the line when a matching word is found in a particular line. Below is the code I am using. But if there are many lines that has the matching word, it's taking lot of time. Any solution to print the lines much faster.
Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if(line.contains("xyz")) { System.out.println(line); } }
I'm trying to build a method that can search a binary search tree for a specific target and then return the number of probes it took to get there. It seems to me that the best way to do this would be a recursive search method and a counter that tracks the number of calls. But I'm struggling with how to implement this. Here's the code I have so far. what works/doesn't work with the method.
// Method to search the tree for a specific name and // return the number of probes public T search(BTNode<T> btNode) {
I am having some trouble with this program. The assignment is to write a program, given a seven-digit phone number, uses a PrintStream object to write to a file every possible seven-letter word combination that corresponds to that number. I have to avoid using 0 or 1. Here is my code.
import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Scanner; public class TelephoneGenerator { String phoneNumber; char numberLetters[][] = {
[Code] ....
I am getting an error dealing with the main class.
I got a phone number problem. I get a list of phone numbers and a word file containing words, how could I need to see if I could match the phone number to 7 letter words, then see if I can match the first 3 numbers to 3 letter words and then the last 4 numbers to 4 number words. I figured all that out so far. The last part of this assignment is to see if I could match a combination of words together to match the phone numbers.
I have this program where I'm supposed to fill an array with 1000 indices with 1000 randomly generated numbers between 1 and 1000. The program is supposed to check if any of the numbers match an index that is the same value (so for example, the number 4 is in index 4). How to check for that condition, especially using a binary search (I'm also told to use a binary search).
Right now the variable index isn't initialized because I don't know what to initialize it to exactly. How do I check to see if any numbers match the value of the same index?
import java.util.*; public class Identity { public static void main(String[] args) { int [] integers = new int [1000]; // Fill array with randomly generated numbers int [] display = GenerateRandom(integers);
URL....In the mentioned project in this blog I used Spring Web Flow to satisfy some requirements but now that development of the Spring Web Flow stopped I like to check what Faces Flows can present to satisfy the same requirements.From a quick look similarities between Spring Web Flow and Faces Flows are obvious but there is one specific point I like to ask.In SWF it is possible to define flowing element at the beginning of an flow.
which will trigger an event when you will start executing a flow, I look to the Faces Flows flow descriptors but I can see an element that fullify similar requirement.similar functionality built into the Faces Flow or not?And is there a way to configure Faces Flows that it reacts to events from the users like the following.
I have to create a dictionary in java using search trees. I have problems with the methods put() and remove(). Working properly, ie correctly adds a new element and eliminates correctly. But I should improve a few things.
As you can see from the interface, both methods must return an element of type V, that is:
- case put(): returns the previous value associated with key (or null if the key was not associated with any value) - case remove(): returns the value associated with the key (or null if the key was not present in the dictionary)
I do not understand how come my put method always returns null even though in reality I make him return node.getElement().
Instead, the remove() method does not know how to modify it to make sure it returns the value associated with the key. If I change the helper method return value in V (instead of Node<K, V>) method does not work anymore...
How can I then edit these two methods?
Class SearchTree: public class SearchTree<K extends Comparable, V> implements Dictionary<K, V> { public int size; public Node<K, V> root; public SearchTree() { root = null; size = 0;
Code for search number from tuple tree? I want to add into my code below. My idea below is to search number from the tree and then print the number. For example, enter input for event is 4, input for strength is 3. Then generate tuple tree. Then user enter number for searching. That number will check every branches in the tuple tree. Then it will printout the number.
Main class code.
package treejava.main; import java.util.Scanner; import treejava.utils.TreeUtils; public class MainClass { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("----Welcome to the Tree Java-Based program-----");
I am working on a little nothing project, but I wanted to create a random number generator for a silly game where the user guesses the number.I have used google, but they are using LOG statements, what it does.
In a text file, I have individual titles (starting with ">" character), and under those titles, I have calculated values for a Counter. I want to search the entire text file for the highest counter under every title. After I get the highest counter, I would like to print it's title, name of the counter, and counter value. Example of the code I already have:
int letterCounter; String line; if (line.startsWith (">")) { bw.write (""); bw.write (line); } else { //code that counts how many total letters (letterCounter) under title }
I just recently started coding java and i have a problem.... So I was doing an exercise on LearnJavaOnline. The exercise was: Create all the the primitives with different values. Concatenate them into a string and print it to the screen so it will print: H3110 w0r1d 2.0 true.I attempted it and this is what i wrote
public static void main(String[] args) {
char H = 'h'; byte e = 3; short l = 1; int L = 1; long o = 0; char w = 'w';
[code]....
However it prints "109 w0r1d 2.0 true".But when i add 2 speech marks: String HelloWorld = H+""+e+l+L+o+" "+w+0+r+one+d+" "+two+" "+hi; It works perfectly.
I am trying to create an empty array that has no assigned length as the amount of elements it needs to hold will be dependent on another value. I then want to use a while loop to assign values to it. Here is an example of what im looking for it doesnt work. Iam trying to do:
int x = 12; int i = 1; int k = 0; int[] factors = {} while (i<x) { if (x%i==0) { factors[k] = i; k++; i++;
Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values . The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered.
No input prompt Terminate input by typing CTRL/Z (two keys typed at the same time) on a separate input line (use CTRL/D on Linux/UNIX systems) Use hasNextInt() to terminate your input Format as below (slightly different from the text example) Z:dbraffittWeek10> javac Histogram.java Z:dbraffittWeek10> java Histogram
[Code] ....
What I can not figure out is how to use hasNextInt() to terminate the loop. How to not have an input prompt. How to use ctrl z to terminate the input. Or to make it where it doesn't involve range values like -1.
import java.util.Scanner; public class Histogram { public static void main (String[] args) { Scanner scan = new Scanner (System.in); int [] nums = new int[101];
Started learning about Array's I'm doing an exercise where you create a for loop that randomly assigns values to each element within the array, but where is my code going wrong?
import java.util.Scanner; public class ArrayExamples{ public static void main(String[] args) { Scanner input = new Scanner(System.in); double exampleArray[] = new double[5]; System.out.print("Enter a Number: "); int num1 = input.nextInt();
How to get used to program control statements. This is an attempt to write a program that returns the number of days between two dates. Sadly, it give incorrect values.
public class DaysBetweenDates { public static boolean isLeapyear(int year) {//This method will determine if a year is a leap year or not boolean isTrue=false; if(year%4==0 && year%100!=0) isTrue=true; else if(year%400==0) isTrue=true; return isTrue;
Here is my problem: if I want to add a number of X consecutive values in an array and get the minimal total value along with the indexes that caused this result, how can I do that?
For example:
X = 2 array[4] = (5,2,8,6,7)
start adding every 2 consecutive values as following:
I have the following task given to me (to be solved in NetBeans) :
View the contents of the file tuinman.txt: each line has a (real) number, followed by a line text.
Write the readGardener () method that reads the file completely. Only if the number is negative, write the rest of the line. (For each input line, a new line output.)
Extra: Adjust your method so you get the text after each negative number, written "word by word", among themselves. A word can contain characters that are not "letters" are (,,. '") - ,this you may ignore.
"tuinman.txt" is dutch for "gardener.txt". This txt file is located in the same map where build,nbproject,src, etc... are located. I couldn't solve this task so i looked at the solution. It didn't work... So i tried the solution of the extra bit:
public class Methods { public void readGardener() throws FileNotFoundException {
[Code] ....
The txt file is added as an attachment to this post.
The weird thing is, the first thing the program prints is "Van" "morgen" "ijlt",... wich are words from line 19 in the txt file. All the ones before line 19 the program won't print, even if the number is negative. Even weirder, the next thing that is printed after line 19 is the NUMBER from line 20, nowhere in this code do i tell the program to print a number, and yet it does... But that's not all! From line 19 on, he just prints every single thing in the document except for the negative number, if your mind didn't explode already, it sure did now!
So in short: I need some code that prints all the lines from the txt files that start with a negative number. Only the text may be printed though, there may be no numbers in the output!
The txt file, i couldn't add it as a attachment
123 -456,12 De tuinman en de dood 184,67 was hij, Kees, de enige die het zag, want niemand lette d'r op... -845,14 -8,12452 Een Perzisch Edelman: 157,24 Dus daar gaan we dan.
/* Purpose: To write the methods and the rest program. The program should fill a 4 X 4 2 dimensional array with random numbers between 100 and 200. The program should then determine and print the largest and smallest values within the array using two Methods Largest and Smallest. The program should then determine and print the number of values within the array that are even using a function called Even. The program should also enter a loop that will only terminate when the user inputs a -1 as a choice. The loop should continue to ask the user to guess a number that was randomly generated. The program should call the Findit function to determine if the number was in the array. The program should print out the values in the array when the user selects a -1 and then terminate. */
import java.util.Scanner; import java.util.Random; public class LNFI_2DArray { public static void main(String[] args) { int guess; int[] array = new int[4];
[Code] ....
I just had this code working, then all of a sudden i was hit with a 'keyboard leak' error code.