Whats wrong in this code?

Sooo... I wanted to make a password reader where the user types the word "password" and it says that the pass is right, but it's always saying that it is wrong and i dont know why! https://code.sololearn.com/c7QnityP4t6R/?ref=app

7/18/2019 3:21:26 AM

Diogo H.

2 Answers

New Answer


The issue is that passtry is an instance of the Scanner class, which won't ever equal "passcode". The Scanner.nextString method returns the string, so you can take this value and save it to a variable, then print that variable and compare it with "passcode". I've made a code to demonstrate this. https://code.sololearn.com/c0MDtZL33QZh/#java


Ohhhh got it, so the equals() only works if both are strings. Thanks you so much!