For some reason, whenever I try to push my objects onto a stack, I get a null pointer exception. This is what I have:
private Stack<BSTnode<K>> myStack;
private void preOrderTrav(BSTnode<K>...
Type: Posts; User: colerelm
For some reason, whenever I try to push my objects onto a stack, I get a null pointer exception. This is what I have:
private Stack<BSTnode<K>> myStack;
private void preOrderTrav(BSTnode<K>...
I have an array,
private T[] elements;. I would like to do this ideally:
if(elements[index] == null){
elements[index] = 0;
}
elements[index] = elements[index] + 1;
I want to output to calculate the following:
0 - (3/6)logbase2(3/6) = 1/2
I have this in my program:
double ratio = 3/6;
x = x - (ratio * (logbase2(ratio)));
which should equal .5 but I...
I found documentation for a class that has some methods I really find useful located at this website.
Is the code for these methods publicly accessible through this webpage or should I email the...
I've asked myself that many times. This is my train of thought:
"What's the biggest number we have to search for?" --I have a function that will tell me this so I have this part solved.
"How many...
I'm struggling to wrap my head around how I could calculate a seemingly simple algorithm and am wondering if anyone can provide some guidance.
I have a 2D array of type int that stores one digit...
Does anyone know of any equivalent class in Java that has similar properties of a DataTable from C#?
Transitioning over to Java from C# and was just curious.
Thanks
What if I have an equals method in my player class but I want to compare two player objects outside that class? How could I, for example, check to see that an element of an array of type player is...
I have a list which I save by the following:
public void saveList(ArrayUnsortedList<Wrestler> listOfWrestlersToSave) {
System.out.println(listOfWrestlersToSave);
try{...
I have two objects, player1 and player 2. These two objects have properties: String first name,String last name, double weight and int grade. I want to create a method that takes in a player object...
If I have a switch-case block like:
switch(i){
case1:
blah1;
break;
case2:
I have an assignment that's asking me to create a method which "Implements the compareTo method provided by the Comparable interface. Allows two objects to be compared based on sortKey(sortKey is...
If I have a list of strings within an array, say:
[0] = jones
[1] = apple
[2] = struggle
[3] = zebra
How can I alphabetize them and place them into another array, in correct alphabetical order?
I have a java program to write and the professor gave us a UML diagram to follow. It all makes sense except for the part where there are dollar signs. What do these dollar signs mean? Here's what it...
I am working with this bit of code for this question:
public boolean remove (T element)
// Removes an element e from this list such that e.equals(element)
// and returns true; if no such...
Why is it that this method returns true? I'm supposed to write an equals method that returns true if both rectangles are similar (My assumption of a "similar rectangle" is one which has the same...
I tried that...It still didn't work :\
The string value doesn't become changed at all
I have a program that prompts the user for an entry and they could potentially enter in a lot of things, but I want to catch the dollar signs and convert them to "" in terms of strings. I've tried...
lol that's what im trying to figure out....What I've thought of so far was thinking of it as a distance or absolute value....Or maybe even finding the median between both numbers and going from...
Say I have three numbers A, B and C. How would I check if B lies between A and C without assuming that A < C or A > C?
I have a question from my assignment which I don't entirely understand. Can anyone please look at it and see if it's as easy as I thought it was or if I'm wrong, in which case can anyone help? This...
public static int puzzle(int base,int limit){
if(base>limit){
return -1;
}
else
if(base==limit)
return 1;
else
return base * puzzle(base+1,limit);
}
This was a homework assignment given to me and I got the answer (listed later), but I was wondering if anyone could check it over and see if i'm correct:
a)
//Assume that you can store and...
How would I create a shallow copy of a stack? The interface method which I must implement is:
MyStackInterface<T> copy();
// Returns a shallow copy of this stack
It doesn't make sense to...
So today I got this programming assignment which is due in a week but I don't even understand what is being asked of me. Since my professor sucks at getting back to me via email, I have come to the...