Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
What are you trying to do in the if statement?if ( s == XRay )
If you don't understand my answer, don't ignore it, ask a question.
Please be more specific and not use words like this and it. I can't read your mind.how to do this or where to put it.
If you don't understand my answer, don't ignore it, ask a question.
How do you define XRay, I do not know how to put that code in or where exactly to put it. I don't understand the difference between a variable and a string.
Alright I've almost got it, all I need to do now is define XRay as the password.
import java.util.Scanner; public class Password{ public static void main(String[] args) { Scanner kbReader = new Scanner(System.in); System.out.println("Enter your password. "); String myPassword = kbReader.nextLine(); if ( myPassword == "XRay" ) System.out.println("Password entered successfully."); else System.out.println("Incorrect password."); } }
New topic: comparing the contents of objects. Strings are objects. If you want to compare the contents of two objects you need to use the equals() method:if ( myPassword == "XRay" )
myPassword.equals( "XRay" )
If you don't understand my answer, don't ignore it, ask a question.