Need help in Computer Science....

[quote name='mtxbass1']no. Let me give you a simple example.

String word = null;

System.out.println(word.length());

This would throw a null pointer exception.

String word = null;
word = "test";
System.out.println(word.length());

This wouldn't.

See the difference? You need to initialize trav in your code.

StringNode trav = null; declares the variable. It still must be initialized.[/QUOTE]

Ahh, I see.

What should I have it intialized to? After declaring it null, I set it equal to curr.
I'm just not sure if it's just pointing to the original str; or actually making a new copy. (what gets printed out now is "FINE")
 
You need to initialize trav to a stringNode object before you point it to something.

This is a poor example, but here goes;

StringNode trav = new StringNode(whatever the constructor is);

Then you can do whatever you want with it.
trav.ch = whatever;
 
StringNode curr = str;
StringNode trav = new StringNode(curr.ch, curr.next);
int length = str.length(str);

while (curr != null){
for (int i = 0; i < length; i++){
trav.ch = str.ch;
}
curr = curr.next;
}

return trav;
}
 
StringNode trav = new StringNode(curr.ch, curr.next);

That line is effectively doing a copy, making the rest of the code a waste. I don't know why I'm bothering as you obviously don't care about any bugs/problems with your existing code as long as it appears to spit out the proper result.
 
[quote name='wubb']StringNode trav = new StringNode(curr.ch, curr.next);

That line is effectively doing a copy, making the rest of the code a waste. I don't know why I'm bothering as you obviously don't care about any bugs/problems with your existing code as long as it appears to spit out the proper result.[/quote]

I understand giving the OP a little guidance but it seems he wants everyone else to write his code for him in its entirety while not attempting to understand the code himself. When I was in CS(graduated 2 years ago) i would ask for guidance but never to this extent. IMHO he should have well more than enough to get him started. No offense to the OP but the answers are in the book in the form of concepts and examples that you need to learn. Its one thing if you have a problem understanding a concept but cheating if you want others to debug your code so you get the correct results.
 
kk, thanks for the all the help guys, but michaema is right....I'm just gonna ask my TF for assistance since I'm obviously hopelessly clueless right now.

Thanks for the help, everyone.
 
[quote name='michaema']I understand giving the OP a little guidance but it seems he wants everyone else to write his code for him in its entirety while not attempting to understand the code himself. When I was in CS(graduated 2 years ago) i would ask for guidance but never to this extent. IMHO he should have well more than enough to get him started. No offense to the OP but the answers are in the book in the form of concepts and examples that you need to learn. Its one thing if you have a problem understanding a concept but cheating if you want others to debug your code so you get the correct results.[/quote]

Exactly what I was hinting at in my earlier posts. I'm not going to provide a solution, but the point was to help someone (hopefully) learn what some of these things mean (such as declaration and initialization).

I have a Masters in Computer Science, as well as a Bachelors in both Computer Science and Math, so I'm used to seeing students like this. Like I said earlier, they may get through this one assignment, or class, but eventually it will hit them like a ton of bricks that they don't understand the core concepts.
 
[quote name='mtxbass1']Exactly what I was hinting at in my earlier posts. I'm not going to provide a solution, but the point was to help someone (hopefully) learn what some of these things mean (such as declaration and initialization).

I have a Masters in Computer Science, as well as a Bachelors in both Computer Science and Math, so I'm used to seeing students like this. Like I said earlier, they may get through this one assignment, or class, but eventually it will hit them like a ton of bricks that they don't understand the core concepts.[/quote]

I saw you make several posts along the same lines, and I thought it needed to be posted again. Masters huh? I stopped at the BS in Computer Science and minor in math. Congratulations on your hard work
 
[quote name='michaema']I saw you make several posts along the same lines, and I thought it needed to be posted again. Masters huh? I stopped at the BS in Computer Science and minor in math. Congratulations on your hard work[/quote]

Thanks. It's finally paying off. I'm about to accept an offer with a new firm.
 
bread's done
Back
Top