File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes string.equals( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string.equals("");" Watch "string.equals("");" New topic


Timos Mann

Joined: Sep 23, 2010
Posts: 6
Hey guys. Im sorry if my question will be a little vague and "noob" but i have this problem ive been thinking for 2 hours and im tired,i hope maybe you can help again.
I read a string from the keyboard and i use an if to determine what "word" is it. The if (xx.equals("exit"){ seems to be working fine,but the other two don't.Its so simple i cant think whats going wrong...
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

chester Man wrote:The if (xx.equals("exit"){ seems to be working fine,but the other two don't.

It would help if you described what "don't seem to be working fine" actually means in your environment.
Timos Mann

Joined: Sep 23, 2010
Posts: 6
Thanks for fast reply Paul. Well,im not sure i understand your question,but i mean that, what i wanted to do,is read a string, then say if the string is "B" call the getB method(), if it is "knot" the getKnot method,if it is "exit" make the com true so you exit the loop. So if i enter "exit" it leaves the loop,but entering B or knot doesnt work,its like entering wrong text,back to loop start. I dont know if that was your question.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

So you get the invalid input message? How about printing what that invalid input is:

How To Ask Questions How To Answer Questions
Timos Mann

Joined: Sep 23, 2010
Posts: 6
you were right,i should have seen it. i forgot an (int) in the methods within the if... geez. Thanks Paul, i was totaly stuck
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

chester Man wrote:,im not sure i understand your question...

What he means is TellTheDetails. Your original post said (basically) "this case doesn't work". That doesn't tell us much. does the program choke and die? Does it run the wrong block? Does it run the right block but the code in that block is wrong?

the more info you give people, the easier it is for them to help, and the more likely they will help.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Timos Mann

Joined: Sep 23, 2010
Posts: 6
Yes,im sorry Fred you are right. Im just kind of new to java,plus i was really tired. After finding what was wrong i can say for sure there was no way to get help the way i asked it. Thanks for taking the time to answer my thread though!
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
Never say while (com==false) . . . It's while (!com) . . .

Did you sort your problem out? What did you do? Your last posting leaves us even more confused about what is happening.
I agree. Here's the link:
subject: string.equals("");
It's not a secret anymore!