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 trialLucas Blackburn
534 PointsNot sure what is wrong with this section code. any help appreciated!
Not sure what the error means.
// 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");
}
String secondExample = "hello";
String thirdExample = "HELLO";
3 Answers
George S-T
6,624 PointsTry removing the quotation marks surrounding secondExample: (firstExample.equals(secondExample))
poltexious
Courses Plus Student 6,993 PointsInstead of
if (firstExample.equals("secondExample"))
you have to write
if (firstExample.equals(secondExample))
In this situation you are comparing whether the string "hello" equals the string "secondExample" because you put quotation marks around the secondExample variable, which becomes a string instead of being a variable.
In other words, removing the quotation marks from secondExample, you are referring to the (string) value of your secondExample string variable. In this case hello equals hello. Otherwise, hello does not equal secondExample.
Lucas Blackburn
534 PointsGreat, Thanks!
poltexious
Courses Plus Student 6,993 PointsBest answer would be appreciated :-)