Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCharles Rotenberg
736 PointsI can't tell what is wrong with my code. The syntax says there is something wrong with my if statement line.
Thanks for helping.
// I have imported a java.io.Console for you, it is named console.
if (firstExample.equals("secondExample"));{
console.printf("first is equal to second");
}
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
2 Answers
Steve Hunter
57,712 PointsHi Charles,
A couple of things amiss there.
First, you've used variable names before they've been declared so you need to move your if
statement below the definitions.
Next, you've put secondExample
inside of double-quotes. That makes it a string like "Steve" or "Wednesday" - to use the value stored inside the variable named secondExample
, skip the quotes.
I think that should see you fine. Else shout back!
Steve.
Stone Preston
42,016 Pointsyou need to put the if statement AFTER the strings are created and change the string literal in the equals method to the secondExample variable name
// I have imported a java.io.Console for you, it is named console.
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if (firstExample.equals(secondExample)){
console.printf("first is equal to second");
}
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsThere's a rogue semi-colon in there too:
So to pick up where Stone Preston left off:
I hope that helps.
Steve.
Charles Rotenberg
736 PointsCharles Rotenberg
736 PointsThanks for the help!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsNo problem - I hope it all worked for you.
Steve.