Simple Java Question

It's a simple question I had about Java. I couldn't find anywhere else as good as this place, so I figured I would try, great community here. Sorry if this is the wrong place to ask. Started java a week back, and this is a practice program I came up with. Enter a Pass Word, and if you enter it again correctly, it tells you you have memorized it. No matter what I enter, it tell's me I have not memorized it, even if I enter the correct password twice. Thank you all for your help.


import java.util.Scanner;

public class Memo {

	public static void main(String[] args) {
		
                System.out.println("* This is the password memorization test. \n* Please enter the password you would like to remember: ");
		Scanner scan1 = new Scanner(System.in);
		String pw = scan1.nextLine();
		System.out.println("Leave this program open for an hour, and if you come back having memorized the password you entered, you have memorized it!");
		System.out.println("Please enter the password you previously entered: ");
		String answer = scan1.nextLine();
		
                if (pw == answer){
			System.out.println("You have memorized your password!");
		}
		else{
			System.out.println("You have not memorized your password. Re-start the program and try again!");
		}
	}
	
}


Thanks M4ster r0shi! I haven't learned that yet, my guide hasn't mentioned it, but it fixed the problem! Changed to

 if (pw .equals(answer)){
			System.out.println("You have memorized your password!");
		}
		else{
			System.out.println("You have not memorized your password. Re-start the program and try again!");
		}
Topic archived. No new replies allowed.