
-----------------------------------
avsrule247
Mon Feb 12, 2007 6:53 pm

Need to exit a loop
-----------------------------------
My program gets input from the user. It checks to see whether the input first letter is between A or H, I or P, or Q and Z. That works fine. But when the user enters the word "stop", the program is supposed to stop. What is the problem?


import java.io.*;

public class example10
{
    public static void main (String 

Please keep in mind that I am totally new to java, and have just learn't the basics.

-----------------------------------
wtd
Mon Feb 12, 2007 6:58 pm

RE:Need to exit a loop
-----------------------------------
What does == do for objects?

-----------------------------------
avsrule247
Mon Feb 12, 2007 7:02 pm

RE:Need to exit a loop
-----------------------------------
Ohhh yes! I must use compareTo. 

Thanks for your help. I knew it was just a simple mistake that I made.

-----------------------------------
wtd
Mon Feb 12, 2007 7:51 pm

RE:Need to exit a loop
-----------------------------------
Are you sure compareTo is the best answer?

Are there any other methods that might work better?

-----------------------------------
avsrule247
Mon Feb 12, 2007 9:09 pm

Re: Need to exit a loop
-----------------------------------
Well, I only know of compareTo, since I just started to learn java 4 days ago. I'm sure there are better ways though.

But if you have any suggestions I'd be more then happy to attempt to use them. :)

-----------------------------------
wtd
Mon Feb 12, 2007 9:12 pm

RE:Need to exit a loop
-----------------------------------
Well, you're checking for _____, which sounds like the name of which method defined for all Objects?  

I'm not just torturing you here.  I'm just trying not to give out easy answers.  :)

-----------------------------------
avsrule247
Mon Feb 12, 2007 9:35 pm

RE:Need to exit a loop
-----------------------------------
Well, let's see...

I am checking the value of the string? A variable? The ascii codes of the first letter? I have no idea. All I know is that I am sorting.

You are very good at torturing. Although I don't blame you, I would have done the same thing. :)

-----------------------------------
ericfourfour
Mon Feb 12, 2007 10:54 pm

RE:Need to exit a loop
-----------------------------------
*cough* equality *cough*

-----------------------------------
avsrule247
Tue Feb 13, 2007 12:10 pm

Re: Need to exit a loop
-----------------------------------
Yeah, that mite work. It's just too bad that I don't know how to use it. :)

-----------------------------------
ericfourfour
Tue Feb 13, 2007 4:45 pm

RE:Need to exit a loop
-----------------------------------
google: "java Object" (or even better "java String")

The javadoc will be the first link. Look for the method used to determine equality between objects.
