0

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

18th Jul 2019, 3:21 AM
Diogo H.
2 ответов
+ 1
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
18th Jul 2019, 3:30 AM
JS Coder
+ 1
Ohhhh got it, so the equals() only works if both are strings. Thanks you so much!
18th Jul 2019, 3:32 AM
Diogo H.