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

Reply

Join Date: Aug 2004
Posts: 11
Reputation: srthomso is an unknown quantity at this point 
Solved Threads: 0
srthomso srthomso is offline Offline
Newbie Poster

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

 
0
  #1
Aug 10th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 55
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

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

 
0
  #2
Aug 10th, 2004
if(reply == "JAVA"){
make this code as :

if(reply.equals("JAVA");

now it'll work properly. Strings are not compared by ==.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 11
Reputation: srthomso is an unknown quantity at this point 
Solved Threads: 0
srthomso srthomso is offline Offline
Newbie Poster

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

 
0
  #3
Aug 10th, 2004
Thank you very much for your help - much appreciated!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC