Question about simple Java program

Write your question here.

closed account (18hRX9L8)
?

First of all: This is a C++ forum. Everything Non-C++ goes in Lounge.
Secondly: Why???
Last edited on
Sorry about that, computer glitched. It's a simple question I had about Java. I couldn't find anywhere else as good as this place, so I figured I could 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 PW, and if you enter it again correctly, it tells you you have memorized it. No matter what I enter, it tell's me I'm incorrect. 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!");
		}
	}
	
}


Last edited on
Just going to take your advice and post in the Lounge, thank you! Marked this as solved.
Last edited on
Topic archived. No new replies allowed.