#Problem with scanner and an if statement

1 messages · Page 1 of 1 (latest)

wanton mortar
#

When i type Alejandro, it outputs the brave message, not the stupid message

steel topazBOT
#

<@&987246399047479336> please have a look, thanks.

crimson briar
#

because you are checking for object identity

#

if you want to check if the strings contain equal letters then you need to use .equals()

wanton mortar
#

Im not sure i understand

#

playername is an independant variable, not from the object, it just gets put in it

crimson briar
#

playername contains a String Object. if you enter "Alejandro" then it is a String Object with the value "Alejandro" and then you are checking for object identity with == so if both Objects are stored at the same memory address and you are comparing to an other String Object, the String literal "Alejandro" you wrote in your source code and since these are two different Objects, they are stored at two different memory addresses so ==is false

#

for checking if both have the same value "Alejandro" you have to use .equals()

wanton mortar
#

ohhhh

#

I see

#

im used to languages like python, sorry

#

Thanks

#

!close

magic bear
wanton mortar
#

true

#

how do i close this?

magic bear
wanton mortar
#

thanks