Computer Science Canada Need to exit a loop |
Author: | avsrule247 [ Mon Feb 12, 2007 6:53 pm ] | ||
Post subject: | 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?
Please keep in mind that I am totally new to java, and have just learn't the basics. |
Author: | wtd [ Mon Feb 12, 2007 6:58 pm ] |
Post subject: | RE:Need to exit a loop |
What does == do for objects? |
Author: | avsrule247 [ Mon Feb 12, 2007 7:02 pm ] |
Post subject: | 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. |
Author: | wtd [ Mon Feb 12, 2007 7:51 pm ] |
Post subject: | RE:Need to exit a loop |
Are you sure compareTo is the best answer? Are there any other methods that might work better? |
Author: | avsrule247 [ Mon Feb 12, 2007 9:09 pm ] |
Post subject: | 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. ![]() |
Author: | wtd [ Mon Feb 12, 2007 9:12 pm ] |
Post subject: | 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. ![]() |
Author: | avsrule247 [ Mon Feb 12, 2007 9:35 pm ] |
Post subject: | 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. ![]() |
Author: | ericfourfour [ Mon Feb 12, 2007 10:54 pm ] |
Post subject: | RE:Need to exit a loop |
*cough* equality *cough* |
Author: | avsrule247 [ Tue Feb 13, 2007 12:10 pm ] |
Post subject: | Re: Need to exit a loop |
Yeah, that mite work. It's just too bad that I don't know how to use it. ![]() |
Author: | ericfourfour [ Tue Feb 13, 2007 4:45 pm ] |
Post subject: | 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. |