Ask coding questions

← Back to all posts
Why isn't this executing all the way through?
DavidMcConnachi (4)

Hopefully this posts right.

I have some print statements throughout the code and they are numbered in the order that the program should reach them and print them in. When I put this on tutor, it will go all the way through and print them all, but when I use, or intelliJ it only makes it to "made it1". Can anyone point out why?

Answered by Scoder12 (433) [earned 5 cycles]
View Answer
Scoder12 (433)

The reason it is not working is because == checks if strings are the same instance which will never be true since strings are immutable (you get a new instance each time). You are looking for the .equals() method which will check if the strings are equal.

if (problem_set.equals(problem_set_y))

For more information, see this stack overflow question.

I am a helper. If this is a good answer, please upvote.

DavidMcConnachi (4)

@Scoder12 Thank you. New to Java. Program just switched from Python. Still trying to get the new syntax down.

Scoder12 (433)

@DavidMcConnachi actually same I just learned java as well. A lot of these things you can just google though.

DavidMcConnachi (4)

@Scoder12 I do a lot of googling for my issues. I couldn't find out why this wasn't working though. Honestly, I'm still confused as to why it would go through and print all the markers on pythontutor(javatutor), but it wouldn't go through on, or intelliJ. I appreciate your help, the code is done now.