943,682 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 5483
  • Java RSS
Aug 10th, 2004
0

code repeatedly 2 ask user 4 a password until correct (=Java) but cant c wots wrong.

Expand Post »
here's the code:

string reply;
reply = getLineFromUser(); //assume this function works correctly
if(reply == "JAVA"){
System.out.println("OK to continue");
}
else {
System.out.println("Error - try again!");
}

i cant seem to see where i'm going wrong, thus cant get a correct version to work. I need it to keep repeating asking for a passwrod until its correct. Password equals JAVA.
Hope some1 can help, cheers.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
srthomso is offline Offline
11 posts
since Aug 2004
Aug 10th, 2004
0

Re: code repeatedly 2 ask user 4 a password until correct (=Java) but cant c wots wrong.

if(reply == "JAVA"){
make this code as :

if(reply.equals("JAVA");

now it'll work properly. Strings are not compared by ==.
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Aug 10th, 2004
0

Re: code repeatedly 2 ask user 4 a password until correct (=Java) but cant c wots wrong.

Thank you very much for your help - much appreciated!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
srthomso is offline Offline
11 posts
since Aug 2004

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.
Message:
Previous Thread in Java Forum Timeline: Any chance of a little help?
Next Thread in Java Forum Timeline: Full Screen





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC