I am inputting a file that has the system output when pinging an ip address. i have gotten it to read the file into an arraylist with readLine. Is there a way to have it input to list using spaces instead of lines?
BufferedReader bf = new BufferedReader(new FileReader(file)); int linecount = 0; int numberTimes = 0; String line; //loop thru file and add contents to an arraylist while ((line = bf.readLine()) != null) { inLine.add(line); } bf.close(); System.out.println(inLine);
I'm trying to implement a Binary Search Tree that accepts strings. I cannot figure out how to compare the string value in my add method against the node object. While I could make the node class data be the string type I am trying to make the code be as reusable as possible. So my question is this, is there a simple way I can compare the two that I am missing?
public class BTNode<E> { private E data; private BTNode<E> left, right; //constructor public BTNode(E initialData, BTNode<E> initialLeft, BTNode<E> initialRight) { data = initialData; left = initialLeft; right = initialRight;
Which string method to search a particular character in a string whether a particular character is there or not . Suppose my String is like............
String s = "Java.";
How I can find the character " . " in above string "Java." is present or not . What is the string method to search that "."
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 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'm trying to create a booklist in java using swings but I'm facing a problem. I don't know how to add a search function to my list. I need a search box with the book names.
Knowing that a hashmap does not sort the keys, I am thinking of using/converting to treemap which by nature does sort out the keys. I now need to find out if it is possible to search a treemap using partial keys such that for example I would like to search for all entries that have a key starting with "78BOX" whilst the available keys are:
The above list is probably how treemap would sort out the keys however need to extract only those keys that start with "78BOX" - does treemap has this functionality ?
// 1 ***** student writes this method /** Searches for key in integer array named arr // arr is an instance variable of the class and has been instantiated and filled with random values. // @param key value to search for // @return if key is found, the index of the first element // in array whose value is key; if key is not found, // the method returns -1 */
public int sequentialSearch( int key ) { // Note: To animate the algorithm, put this method call as the first statement in your for loop // animate( i, 0 ); // where i is the index of the current array element return 0; // replace this statement with your return statement } // end of sequentialSearch
Okay, so the assignment was creating a word search for the given array. I've created all the code necessary, but I've ran into trouble. This problem occurs with the Up-Forward, Up-Backward, Down-Forward, and Down-Backward sections. If I only set one of these to run, it works. But if I have all 4 set at the same time, it errors out on the first one that runs.
public class P_WordSearch { public static void main(String[] args) { char[][] puzzle = { {'B','O','O','G','S','R','O','W','I','N','G'}, {'E','B','L','G','N','I','M','M','I','W','S'}, {'L','C','E','A','T','I','P','U','P','I','S'}, {'C','M','I','N','C','A','X','Y','O','S','N'},
We have this piece of code and we must make a search for a key. if the key exist it returns true if not false. Plus we must insert a key in the class. If it is already in there we say hey its already in and we don t put it again...
package askisi2; import java.util.*; public class mtree { protected class tnode { public int k1; public int k2; public int k3;
I am pretty new to Java and I am working on a sample Search code from my textbook. I can't figure out why I am getting the following error because I copied the sample exactly as it is in the book. The error is illegal start of expression on the second to last line.
public class Search { public static final int NOT_FOUND = -1; public static int binarySearch( int [] a, int x ) { int low = 0; int high = a.length - 1; int mid;
I am trying to make a program that compares the 3 different search algorithms(sequential/binary/hashing). I have already made the sequential search algorithm, binary and hashing part of the code.My program OPENS a data file, and then OPENS a key data file. and then searches through them using both. How to go about the binary and hashing search algorithm (in the driver program).
*I have included a zip file with: -base program -driver program -data file -key data file
I have always wanted to program A*, Breath First Search and Depth First Search ever since I took AI. I will only post BFS at the moment but it is only searching the row.
Java Code:
//Breath First Search. The first node passed to it is the start button void bfs(Mybuttons button){ Queue<Mybuttons> q = new LinkedList<Mybuttons>(); q.add(button); button.setIcon(button.setButtonToBlueWhileSearched()); button.model.visted=true;
[Code] ....
Output:
Java Code: In while loop In get Child Node In get Child Node In get Child Node In get Child Node In while loop In get Child Node In get Child Node In get Child Node In while loop In get Child Node In get Child Node In while loop In get Child Node mh_sh_highlight_all('java');
I am having some trouble with linear search of a customers last name. I can't seem to get it to work. I have looked up examples but cant find many with Array Lists. Here is my code.
import java.util.ArrayList; import java.util.Scanner; public class AccountDriver { public static void main(String[] args) { ArrayList<Account> al = new ArrayList<Account>(); ArrayList<Customer> cust = new ArrayList<Customer>(); Scanner scan = new Scanner(System.in);
I'm trying to make a update page where you search for person info by their number then have the ability to change any info and save it back to the binary field. I have the search working but i don't know how to do the update,.here my code:
I try to create a jsf project within ejb which is add new car with entering attributes listing attributes and search by make.
Add and list methods working well , but have problem of list method. I tryed many combinations (using enhanced loop, iterative loop) but i cant provide working well. Always outputText returns nothing ,when i enter attributes.
Here is ejb code for adding ,getting and listing car items :
@Stateful public class CarsBusiness implements CarsBusinessLocal { List<Car> cars; public CarsBusiness() { cars = new ArrayList<Car>();
I have created a binary search with 3 subsets, some aslo call it a ternary search and have come up with a minor problem. If you run the code as posted below it just runs until you quit it. If anyother value in the array is searched it is found.
/* public class BinarySearchDemo { public static void main(String[] args) { String[] songs = {"Ace Of Spades", "Beyond the Realms Of Death", "Breaking The Law",
How do I make it so I am able to enter any number rather then just the numbers in the arrays? I want it to be able to find the position of any number between 0-100.
import javax.swing.*; public class BinarySearch { public static void main(String[] args) { int array[] = new int[11]; array[0] = 10; array[1] = 20; array[2] = 30; array[3] = 40; array[4] = 50; array[5] = 60;
The point is to use a binary search to determine how many steps it would take to get to int X, int Y in a grid that is N by N. Picture a parking lot that is square and your car is at (x,y). You can honk your horn from your key to determine the direction of the car. I need to return the amount of steps to get to the car. You can't step diagonally. I am currently getting an error that causes an infinite loop and I can't fix it.
public class ParkingLot { public int search(int N, int X, int Y) { int minX = 0, maxY = N, minY = 0, maxX = N; int num = 0; int curX, curY; int newCurX, newCurY; curX = (minX + maxX)/2; curY = (minY + maxY)/2; while (curX != X || curY != Y)
This method uses BFS traversal on a vertex and displays the values. I have worked this out on paper and 2 out of 3 the results from my code match my work on paper. I believe the error is that it prints out 3's adjacent child before 3 itself. I have attached the results I did by hand. Here's the graph and results from my code: