954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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.

srthomso
Newbie Poster
11 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

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

if(reply.equals("JAVA");

now it'll work properly. Strings are not compared by ==.

nanosani
Unauthenticated Liar
Team Colleague
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
 

Thank you very much for your help - much appreciated!

srthomso
Newbie Poster
11 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You