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 trial

Java Java Basics Perfecting the Prototype String Equality

Don't understand this task.

I can't get this to work.

Equality.java
// 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.");
        System.exit(0);

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

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 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.