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 trialKevin Hippert
413 PointsI don't get it why this should be wrong?
Why should this be wrong and why I get an error message?
// I have imported a java.io.Console for you, it is named console.
String firstExample = "hello";
if (firstExample.equals("secondExample")){
console.printf("first is equal to second");
System.exit(0);
}
String secondExample = "hello";
String thirdExample = "HELLO";
3 Answers
Steve Hunter
57,712 PointsYou have used variables before you have declared them in your code.
So, move the whole if
statement below the variable declarations.
// 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");
System.exit(0);
}
That way, the compiler knows about secondExample
before you use it in your code. (and see the comment below)
Steve.
Kevin Hippert
413 PointsI get it. Thanks Steve for the quick help. :)
Steve Hunter
57,712 PointsNo problem! :-)
Steve Hunter
57,712 PointsSorry - that's me missing your added line. You don't need the System.exit(0)
at all. Delete that line.
Apologies for not seeing that before.
Steve.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsYou also need to remove the double quotes from around "secondExample" - it is a variable, not a string.
Make sense?
Steve.
Kevin Hippert
413 PointsKevin Hippert
413 Pointswtf? This won't work.. :D?
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsOdd. Looks fine - let me get into the challenge - I'll be right back!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsSorry - that's me missing your added line. You don't need the
System.exit(0)
at all. Delete that line.Apologies for not seeing that before.
Steve.