Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype String Equality

Don't understand this task.

I can't get this to work.

// 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("%s", secondexample)) {
        console.printf("first is equal to second.");

I changed 'secondexample' to 'secondExample' in the code, and also firstExample.

2 Answers

Jason Anders
Jason Anders
Treehouse Moderator 145,623 Points

Hey Cameron,

You're pretty much on the right track, except for a couple of things.

In your if statement, you need to compare the values stored in the two variables. Here you are going in the right direction, you have the first variable there and the proper method for equals to but you're comparing it to an interpolated string instead of just the variable. All the .equals requires here is the secondExample variable.

Now, the challenge did not ask for a System.exit(0);, so that line needs to be deleted.

Next is just a small syntax error. You're just missing the closing curly brace for the if statement.

I'll provide the correct code here for you to compare and go through with the explanation.

Hope this helps!

if (firstExample.equals(secondExample)) {
        console.printf("first is equal to second.");

Keep Coding! :dizzy:

Ohhh okay! Thanks for the help. Loving TreeHouse so far, great classes.