Ask coding questions

← Back to all posts
Why is ay != "ay" always true?
Bunnytoes (232)

When I try to remove all characters but 2 to see if it is "ay" but it doesn't work, I don't know why. @Coder100 sorry for ping

Comments
hotnewtop
Coder100 (19280)

Java compares by pointer not value?

Is that not why you used ay.equals(b)?

In other words, to do ay != ... use !ay.equals(b)

for you:

Bunnytoes (232)

@Coder100 I tried, let me show you

Coder100 (19280)

yeah but that's not with ay != "ay" the problem here is as youc an see elsewhere! @Bunnytoes

Bunnytoes (232)

@Coder100 I know, but how do I fix the other thing?

Coder100 (19280)

you made the arguments backwards, do you mean pigy.substring(1, piggy.length() - 1), etc. @Bunnytoes

Bunnytoes (232)

@Coder100 that doesn't work, but I fixed it

Coder100 (19280)

oh i see, perhaps you want to use .get() method to get one character only instead. @Bunnytoes

MrVoo (190)

Try printing the ay variable right before the conditional, it might answer why