part to continue until the user enters "quit". I would like to use a while statement. Every way I have tried to enter phrase not equal to "quit" has not worked. Do I need to declare "quit" somewhere or what? Any help would be greatly appreciated.
, one of two things happens depending on where I place my "}". Option one at the end is it causes an infinite loop or option two if I place the "}" sooner is it does nothing.
so soon? I'm really new with java so please be kind to me.
Phrase is initialized in the code that you posted. It is initialized to "", which is the empty String. In order to quit using the code Masijade showed you, after you say "please enter a sentence or phrase" inside of the while loop, you would need to read in the user's input, then store it into the phrase variable. If that doesn't make sense, then read about the Scanner class. http://java.sun.com/j2se/1.5.0/docs/...l/Scanner.html
Relevant topics: Where it says,
Quote ...
For example, this code allows a user to read a number from System.in:
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
But you cannot read in Strings with the nextInt method, so read about the nextLine() method.
Thx a lot masijade. I finally got it . Can you please explain why that works? I would like to learn. I would have never of figured that out on my own. My knowledge of java is fairly limited.
Last edited by COKEDUDE; Oct 19th, 2009 at 12:44 pm.
Because phrase is a String object, and the "equals" method for the String class is implemented so that it compares two Strings to see if they are the same. If you are interested, you should read about the following topics:
Method overriding
Inheritance
And also, mark solved threads as solved
Last edited by BestJewSinceJC; Oct 19th, 2009 at 1:13 pm.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.